-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.69 KB
/
main.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/lxzan/gws"
)
func main() {
// web serverj
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.DefaultCORSConfig))
wsV1 := e.Group("/v1/ws")
apiV1 := e.Group("/v1/api")
apiV1.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
apiV1.GET("/datacenters", ListDatacenters)
apiV1.GET("/datacenters/:id", FindDatacenter)
apiV1.GET("/rows", ListRows)
apiV1.GET("/rows/:id", FindRow)
apiV1.GET("/rows/datacenter/:id", ListRowsByDatacenter)
// ws upgrader for react
upgrader := gws.NewUpgrader(&WebSocketHandler{}, &gws.ServerOption{
ParallelEnabled: true,
Recovery: gws.Recovery,
PermessageDeflate: gws.PermessageDeflate{Enabled: true},
})
// ws upgrader for log reciver route
logUpgrader := gws.NewUpgrader(&LogReceiverSocketHandler{}, &gws.ServerOption{
ParallelEnabled: true,
Recovery: gws.Recovery,
PermessageDeflate: gws.PermessageDeflate{Enabled: true},
})
// default ws route
wsV1.GET("/connect", func(c echo.Context) error {
socket, err := upgrader.Upgrade(c.Response().Writer, c.Request())
if err != nil {
return err
}
go func() {
socket.ReadLoop()
}()
return nil
})
// log reciver ws route
wsV1.GET("json/dynamic", func(c echo.Context) error {
socket, err := logUpgrader.Upgrade(c.Response().Writer, c.Request())
if err != nil {
return err
}
go func() {
socket.ReadLoop()
}()
return nil
})
// user config
e.POST("/v1/user/config", UserConfigRecieveHandler)
e.Logger.Fatal(e.Start(":1323"))
}