本文主要是介绍Go Gin框架,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、Gin介绍
Gin是一个用Go编写的HTTPweb框架。它是一个类似于martini但拥有更好性能的API框架, 优于httprouter,速度提高了近 40 倍。点击此处访问Gin官方中文文档。
二、安装
1、安装Gin
go get -u github.com/gin-gonic/gin
2、代码中引入
import "github.com/gin-gonic/gin"
代码
package mainimport "github.com/gin-gonic/gin"func main() {//go get -u github.com/gin-gonic/gin 执行get拉取包ginServer := gin.Default() //创建服务ginServer.GET("/hello", func(context *gin.Context) {context.JSON(200, gin.H{"msg": "hello go"})})ginServer.POST("/user", func(context *gin.Context) {context.JSON(200, gin.H{"msg": "创建成功"})})ginServer.PUT("/user", func(context *gin.Context) {context.JSON(200, gin.H{"msg": "修改成功"})})ginServer.DELETE("/user", func(context *gin.Context) {context.JSON(200, gin.H{"msg": "删除成功"})})ginServer.Run(":8082")
}
结果:
这篇关于Go Gin框架的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!