forked from veops/messenger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (39 loc) · 980 Bytes
/
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
package main
import (
"fmt"
"log"
"github.com/gin-gonic/gin"
"golang.org/x/sync/errgroup"
"github.com/veops/messenger/global"
"github.com/veops/messenger/middleware"
"github.com/veops/messenger/send"
)
func main() {
authConf, err := global.GetAuthConf()
if err != nil {
log.Fatalln(err)
}
appConf, err := global.GetAppConf()
if err != nil {
log.Fatalln(err)
}
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
v1 := r.Group("/v1").Use(middleware.Auth(authConf), middleware.Error2Resp())
{
v1.POST("/message", send.PushMessage)
v1.POST("/uid/getbyphone", send.GetUIDByPhone)
v1.POST("/senders", global.PushRemoteConf)
v1.PUT("/senders", global.PushRemoteConf)
v1.DELETE("/senders", global.PushRemoteConf)
}
eg := &errgroup.Group{}
eg.Go(send.Start)
eg.Go(func() error {
return r.Run(fmt.Sprintf("%s:%s", appConf["ip"], appConf["port"]))
})
log.Println("start successfully...")
if err := eg.Wait(); err != nil {
log.Println(err)
}
}