Giter Club home page Giter Club logo

pi-db's Introduction

Pi-db

本文使用go语言的server框架gin 实现在树莓派上提供远程访问数据库(sqlite)服务.

  • 项目结构
.
├── README.md
├── apis
│   └── cpuInfo.go
├── database
│   └── cpu.db
├── main.go
├── models
│   ├── cpu.go
│   └── sqlite.go
└── routers
    └── router.go

在routers中设置好相关的路由(目前只有GET),由apis中来实现,它经由models来实现。

  • 编译与安装
  1. 在电脑平台上先安装 gin:
$ go get -u github.com/gin-gonic/gin
  1. 编译
$ go build
  1. 交叉编译树莓派版本

​ 由于用sqlite 数据库,需要用cgo来编译sqlite对应的版本,需要安装gcc的交叉编译器arm-linux-gcc

​ 把ARMx-2009q3-67.tar.bz2下载后解压放在/usr/local/arm-gcc下:

/usr/local/arm-gcc
├── arm-none-linux-gnueabi
├── bin
├── lib
├── libexec
└── share

b. 再声明环境变量:

$ export PATH="/usr/local/arm-gcc/bin:$PATH"

c. 检验一下是否安装成功:

$ which arm-none-linux-gnueabi-gcc
/usr/local/arm-gcc/bin/arm-none-linux-gnueabi-gcc

d. 编译树莓版本:

$ CGO_ENABLED=1 GOOS=linux GOARCH=arm CC=arm-none-linux-gnueabi-gcc go build
  • 运行

    把生成的目标文件pi-db和文件夹database一起传到树莓派上,启动程序:

$ ./pi-db
  • 访问方法
curl -i http://localhost:8080/api/cpu/T

pi-db's People

Contributors

andy-y-li avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.