1. gin
github地址:https://github.com/gin-gonic/gin
安装gin的代码包
go get github.com/gin-gonic/gin
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
bindAddress := "localhost:2303"
r := gin.Default()
//监听 get请求 /test路径
r.GET("/test", func(c *gin.Context) {
c.JSON(200,[]string{"123", "321"})
})
r.Run(bindAddress)
}
2. gorilla
gorilla拥有很多类库,这次我们使用的是它的webSocket
go get github.com/gorilla/websocket
package main
import (
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"net/http"
)
var upGrader = websocket.Upgrader{
CheckOrigin: func (r *http.Request) bool {
return true