-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (25 loc) · 736 Bytes
/
main.go
File metadata and controls
34 lines (25 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"html/template"
ctrl "github.com/cdyue/websocket/controller"
"github.com/cdyue/websocket/handler"
"golang.org/x/net/websocket"
"github.com/gin-gonic/contrib/gzip"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
templ := template.Must(template.New("projectViews").ParseGlob("templates/*.tmpl"))
r.SetHTMLTemplate(templ)
r.Use(handler.Log()) //log15日志
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.POST("/user", gin.Bind(ctrl.User{}), ctrl.CreateUser)
r.GET("/websocket", func(c *gin.Context) {
handler := websocket.Handler(ctrl.WebsocketCtrl)
handler.ServeHTTP(c.Writer, c.Request)
})
r.GET("/", func(c *gin.Context) {
c.HTML(200, "ws.tmpl", nil)
})
r.Run(":4000")
}