1、go环境
- go环境:go version go1.15.2 windows/amd64
- windows:win10旗舰版
- IDE:vs code
2、gin项目依赖
主工程项目
在github.com文件夹下:
git clone https://github.com/gin-gonic/gin.git gin-gonic/gin
依赖工程:
在github.com文件夹下:
- git clone https://github.com/gin-contrib/sse.git gin-contrib/sse
- git clone https://github.com/go-playground/universal-translator.git go-playground/
universal-translator- git clone https://github.com/leodido/go-urn.git leodido/go-urn
- git clone https://github.com/mattn/go-isatty.git mattn/go-isatty
- git clone https://github.com/ugorji/go.git ugorji/go
- git clone https://github.com/go-playground/validator.git go-playground/validator/
- git clone https://github.com/golang/protobuf.git golang/protobuf
- git clone https://github.com/go-playground/locales.git go-playground/locales
在golang.org/x文件夹下:
- git clone https://github.com/golang/crypto.git crypto
在google.golang.org文件夹下:
- git clone https://e.coding.net/robinqiwei/googleprotobuf.git protobuf
在src文件夹下:
- git clone https://github.com/go-yaml/yaml.git gopkg.in/yaml.v2
3、gin环境测试
在src目录下面建立一个工程:
目录结构如下:
- src
- ginstudy
- main
- main.go
main.go文件内容:
package main
import "github.com/gin-gonic/gin"
func main() {
TestGin()
}
func TestGin() {
r := gin.Default()
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"Blog": "https://blog.csdn.net/xiazhipeng1000",
"wechat": "xxxxxx",
})
})
r.Run()
}
将上面文件的内容复制到main.go中,在src/ginstudy/main/文件夹下,输入如下的命令,启动服务:
go run .\main.go
在本地的浏览器中输入网址,测试网站启动情况:
http://localhost:8080/
如果出现如上的界面说明你的gin已经安装好了。
另附福利:gin的package依赖环境打包:
链接:https://pan.baidu.com/s/1nhrDPOMFo1IPaxfSnHeutw
提取码:y250
有啥不对的地方,希望大家指正哈!
感兴趣的朋友可以关注下面的公众号,每天分享一点知识,成长看得见,感谢支持!!