Gin:Go语言编写的Web框架,以更好的性能实现类似Martini框架的API
net/http足够简单,性能也非常不错package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
// 1.创建路由
r := gin.Default()
// 2.绑定路由规则,执行的函数
// gin.Context,封装了request和response
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "hello World!")
})
// 3.监听端口,默认在8080
// Run("里面不指定端口号默认为8080")
r.Run(":8000")
}Beego:开源的高性能Go语言Web框架
Iris:最快的Go语言Web框架,完备的MVC支持

新建一个Go项目
创建一个main.go文件,当作主入口文件
"github.com/gin-gonic/gin"main.go
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
// 1.创建Gin路由
r := gin.Default()
// 2.绑定路由规则,执行的函数
// gin.Context,封装了request和response
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, "yes")
})
// 3. 监听端口,默认是8080;可以自定义端口
r.Run(":8080")
}启动服务后,在浏览器中输入localhost:8080/ping就能可以访问了
8080端口是通过 r.Run() 方法设置/ping请求路由,通过r.GET/r.POSt/…函数设置