/
server.go
49 lines (42 loc) · 1.01 KB
/
server.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
package http
import (
"github.com/Terry-Mao/goim/internal/logic"
"github.com/Terry-Mao/goim/internal/logic/conf"
"github.com/gin-gonic/gin"
)
// Server is http server.
type Server struct {
engine *gin.Engine
logic *logic.Logic
}
// New new a http server.
func New(c *conf.HTTPServer, l *logic.Logic) *Server {
engine := gin.New()
engine.Use(loggerHandler, recoverHandler)
go func() {
if err := engine.Run(c.Addr); err != nil {
panic(err)
}
}()
s := &Server{
engine: engine,
logic: l,
}
s.initRouter()
return s
}
func (s *Server) initRouter() {
group := s.engine.Group("/goim")
group.POST("/push/keys", s.pushKeys)
group.POST("/push/mids", s.pushMids)
group.POST("/push/room", s.pushRoom)
group.POST("/push/all", s.pushAll)
group.GET("/online/top", s.onlineTop)
group.GET("/online/room", s.onlineRoom)
group.GET("/online/total", s.onlineTotal)
group.GET("/nodes/weighted", s.nodesWeighted)
group.GET("/nodes/instances", s.nodesInstances)
}
// Close close the server.
func (s *Server) Close() {
}