-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.go
70 lines (61 loc) · 1.85 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
package main
import (
"fmt"
"log"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"golang.org/x/sync/errgroup"
"github.com/veops/messenger/docs"
"github.com/veops/messenger/global"
"github.com/veops/messenger/middleware"
"github.com/veops/messenger/send"
)
// main
//
// @externalDocs.description Messenger README
// @externalDocs.url https://github.com/veops/messenger?tab=readme-ov-file#messenger
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()
r.SetTrustedProxies([]string{"0.0.0.0/0", "::/0"})
g1 := r.Group("/v1").Use(middleware.Auth(authConf), middleware.Error2Resp())
{
g1.POST("/message", send.PushMessage)
g1.POST("/uid/getbyphone", send.GetUIDByPhone)
g1.POST("/senders", global.PushRemoteConf)
g1.PUT("/senders", global.PushRemoteConf)
g1.DELETE("/senders", global.PushRemoteConf)
}
g2 := r.Group("/v1").Use(middleware.Error2Resp())
{
g2.GET("/histories", send.QueryHistory)
}
r.StaticFile("/web", "./web/build/index.html")
r.StaticFile("/manifest.json", "./web/build/manifest.json")
r.StaticFile("/logo192.png", "./web/build/logo192.png")
r.StaticFile("/favicon.ico", "./web/build//favicon.ico")
r.Static("/static", "./web/build/static")
// r.Static("/manifest.json", ".web/build/manifest.json")
docs.SwaggerInfo.Title = "Messenger api"
docs.SwaggerInfo.Version = ""
docs.SwaggerInfo.BasePath = "/"
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
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)
}
}