0
点赞
收藏
分享

微信扫一扫

Go的Gin框架学习

高子歌 2022-04-21 阅读 105
golang

框架安装

1、设置代理
在下载gin框架之前,我们还需要配置go公共代理镜像,目的是解决github无法访问或者访问速度慢的问题,在cmd窗口中执行命令:

# 这里我设置成自动模式,on的模式我开启后莫名的无法执行gin代码下载
go env -w GO111MODULE=auto
# 设置代理
go env -w GOPROXY=https://goproxy.io,direct

2、下载gin框架

go get -u github.com/gin-gonic/gin

3、创建demo项目,运行gin框架

package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func main() {
	router := gin.Default()

	router.GET("/", func(context *gin.Context) {
		context.String(http.StatusOK, "HelloWorld")
	})

	router.Run(":3333")
}

4、缺少包报错问题处理
由于网络原因,此处与google相关的包无法访问,需要单独下载

..\github.com\go-playground\universal-translator\errors.go:7:2: cannot find package "github.com/go-playground/locales" in any of:
	C:\Program Files\Go\src\github.com\go-playground\locales (from $GOROOT)
	D:\go_work\src\github.com\go-playground\locales (from $GOPATH)
..\github.com\go-playground\validator\baked_in.go:23:2: cannot find package "github.com/leodido/go-urn" in any of:
	C:\Program Files\Go\src\github.com\leodido\go-urn (from $GOROOT)
	D:\go_work\src\github.com\leodido\go-urn (from $GOPATH)
..\github.com\gin-gonic\gin\logger.go:14:2: cannot find package "github.com/mattn/go-isatty" in any of:
	C:\Program Files\Go\src\github.com\mattn\go-isatty (from $GOROOT)
	D:\go_work\src\github.com\mattn\go-isatty (from $GOPATH)
..\github.com\gin-gonic\gin\binding\msgpack.go:15:2: cannot find package "github.com/ugorji/go/codec" in any of:
	C:\Program Files\Go\src\github.com\ugorji\go\codec (from $GOROOT)
	D:\go_work\src\github.com\ugorji\go\codec (from $GOPATH)
..\github.com\go-playground\validator\baked_in.go:20:2: cannot find package "golang.org/x/crypto/sha3" in any of:
	C:\Program Files\Go\src\golang.org\x\crypto\sha3 (from $GOROOT)
	D:\go_work\src\golang.org\x\crypto\sha3 (from $GOPATH)
..\github.com\gin-gonic\gin\gin.go:19:2: cannot find package "golang.org/x/net/http2" in any of:
	C:\Program Files\Go\src\golang.org\x\net\http2 (from $GOROOT)
	D:\go_work\src\golang.org\x\net\http2 (from $GOPATH)
..\github.com\gin-gonic\gin\gin.go:20:2: cannot find package "golang.org/x/net/http2/h2c" in any of:
	C:\Program Files\Go\src\golang.org\x\net\http2\h2c (from $GOROOT)
	D:\go_work\src\golang.org\x\net\http2\h2c (from $GOPATH)
..\github.com\go-playground\validator\baked_in.go:21:2: cannot find package "golang.org/x/text/language" in any of:
	C:\Program Files\Go\src\golang.org\x\text\language (from $GOROOT)
	D:\go_work\src\golang.org\x\text\language (from $GOPATH)
..\github.com\gin-gonic\gin\binding\protobuf.go:12:2: cannot find package "google.golang.org/protobuf/proto" in any of:
	C:\Program Files\Go\src\google.golang.org\protobuf\proto (from $GOROOT)
	D:\go_work\src\google.golang.org\protobuf\proto (from $GOPATH)

Compilation finished with exit code 1

1)在GOPATH目录的src目录下,新建文件夹google.golang.org,然后cmd窗口中,切换到该目录下,执行命令:
D:\go_work\src\github.com\google.golang.org

git clone https://github.com/protocolbuffers/protobuf-go.git

下载完成后,将protobuf-go目录重命名为protobuf
在这里插入图片描述
2)由于网络原因,此处与golang.org相关的包也无法下载
在GOPATH目录的src目录下,新建文件夹golang.org,然后cmd窗口中,切换到该目录下,执行命令:
D:\go_work\src\github.com\golang.org

git clone https://github.com/golang/tools.git

下载完成后,将tools目录重命名为x
在这里插入图片描述
3)进入x目录,继续执行命令:
D:\go_work\src\github.com\golang.org\x

git clone https://github.com/golang/crypto.git
举报

相关推荐

0 条评论