安装Gin软件包
- 首先需要安装Go(需要1.10+版本),然后使用下面的Go命令安装Gin
go get -u github.com/gin-gonic/gin
- 将其导入代码
import "github.com/gin-gonic/gin"
hello world
package mainimport ("github.com/gin-gonic/gin")func main() {// 1.创建路由r := gin.Default()// 2.绑定路由规则,执行的函数// gin.Context封装了request和responser.GET("/", func(c *gin.Context) {c.String("hello, world!")})// 3.监听端口,默认在8080// Run("里面不指定端口号默认为8080")r.Run()}
