Skip to content

yushuailiu/go-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

项目

基于Gin的Go语言简单REST应用,Go入门学习示例、Go Web开发入门

go安装

Mac上安装

brew install go

环境变量配置

在~/.bashrc 或则 ~/.profile中添加

export GOROOT=/usr/local/Cellar/go/1.10/libexec  //具体参考自己安装的版本
export GOPATH=/Users/lfuture/Documents/goProject/go-rest:/Users/lfuture/Documents/goProject/其他项目地址 // 添加项目地址,第一个目录
填写你即将clone项目在你本地保存的目录
export GOBIN=/Users/lfuture/bin

使配置生效

source ~/.bashrc // 或则 source ~/.profile

配置及运行

git clone git@github.com:lfuture/go-rest.git
cd go-rest
go get github.com/gin-gonic/gin

创建数据库

create database test;
CREATE TABLE `person` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(60) NOT NULL DEFAULT '',
  `last_name` varchar(60) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARSET=utf8

修改数据库

修改mydatabase/mysql.go

SqlDB, err = sql.Open("mysql", "root:yourpassword@tcp(127.0.0.1:3306)/test?parseTime=true")

运行

go run main.go router.go //直接运行
go build                // 打包

访问

即可访问router.go里定义的相应路由~

About

基于Gin的Go语言简单REST应用,Go入门学习示例、Go Web开发入门

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages