Gin

来自linux中国网wiki
Evan讨论 | 贡献2020年6月6日 (六) 08:42的版本 →‎see also
跳到导航 跳到搜索

install

pre install golang

Golang

#apt 
#可以指定版本的
sudo apt install  golang

sudo apt  install golang-go gccgo-go
sudo apt  install golang-go 

install Gin package

 export PATH=/usr/local/go/bin/:$PATH
 export GOPATH=/root/go #if U user is root 

If you're in China

如果您使用的 Go 版本是 1.13 及以上

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct

#or
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct

# 设置不走 proxy 的私有仓库,多个用逗号相隔(可选)
go env -w GOPRIVATE=*.corp.example.com

# 设置不走 proxy 的私有组织(可选)
go env -w GOPRIVATE=example.com/org_name

Go 版本是 1.12 及以下

# 启用 Go Modules 功能
export GO111MODULE=on
# 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io

或者,根据文档可以把上面的命令写到.profile或.bash_profile文件中长期生效


go get -u github.com/gin-gonic/gin #注意 安装一般用下面的goverdor 版本管理 tool 去安装 这一块可以直接跳过 

Use a vendor tool like Govendor

 go get github.com/kardianos/govendor #在墙外非常快
sudo apt  install govendor # apt 
mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"

Vendor init your project and add gin

govendor init
govendor fetch github.com/gin-gonic/[email protected]

#有时要绝对路径  @后面也可以不加  有时一定要加
/root/go/bin/govendor fetch github.com/gin-gonic/[email protected]

trouble

1.6 err

# go   run main.go 
# github.com/myusername/project/vendor/github.com/gin-gonic/gin
vendor/github.com/gin-gonic/gin/context.go:36:26: undefined: binding.MIMEYAML
vendor/github.com/gin-gonic/gin/context.go:600:29: undefined: binding.YAML
vendor/github.com/gin-gonic/gin/context.go:605:29: undefined: binding.Header
vendor/github.com/gin-gonic/gin/context.go:659:31: undefined: binding.YAML
vendor/github.com/gin-gonic/gin/context.go:664:31: undefined: binding.Header
vendor/github.com/gin-gonic/gin/context.go:673:9: undefined: binding.Uri
vendor/github.com/gin-gonic/gin/context.go:896:17: undefined: render.PureJSON
vendor/github.com/gin-gonic/gin/context.go:912:17: undefined: render.ProtoBuf
vendor/github.com/gin-gonic/gin/context.go:1027:7: undefined: binding.MIMEYAML
vendor/github.com/gin-gonic/gin/mode.go:83:2: undefined: binding.EnableDecoderDisallowUnknownFields

see also

Golang包管理工具(一)之govendor的使用

govendor的安装与实践

Govendor使用