如果不想翻墙,请配置如下:
$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.cn,direct
下载安装
go get -u github.com/gin-gonic/gin
go env -w GO111MODULE=auto
go mod init gin gin是随便创建个mod名称,如果在GOPATH有go.mod删除掉就行了
go mod edit -require github.com/gin-gonic/gin@latest
go mod tidy
test.go
package main
import "github.com/gin-gonic/gin"
func main() {
engine := gin.Default()
engine.GET("/", func(context *gin.Context) {
context.String(200, "hello, gin")
})
engine.Run()
}
go run test.go
配置热重启:
需要下载一个包:
go get github.com/codegangsta/gin