-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 1.11 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
package main
import (
"fmt"
"github.com/a-company/yoriai-backend/pkg/config"
"github.com/a-company/yoriai-backend/pkg/handler"
"github.com/a-company/yoriai-backend/pkg/service/line"
"github.com/a-company/yoriai-backend/pkg/util/firestore"
"github.com/gin-gonic/gin"
"log/slog"
"strconv"
)
func main() {
e := gin.Default()
e.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Hello World",
})
})
lineBotSvc, err := line.NewLINEBotService()
if err != nil {
slog.Error("failed to initialize line bot service", err)
return
}
fs := firestore.New()
lineWHandler := handler.NewLINEWebhookHandler(lineBotSvc, fs)
e.Any("/line/webhook", lineWHandler.Handle)
vonageWHService := handler.NewVonageWebhook(lineBotSvc, fs)
e.Any("/vonage/webhook", vonageWHService.Handle)
port := 8080
if config.Config.General.Port != "" {
port, err = strconv.Atoi(config.Config.General.Port)
if err != nil {
slog.Error("failed to load port, invalid format", err)
return
}
}
invokeHandler := handler.NewInvokeHandler(fs)
e.POST("/invoke", invokeHandler.Handle)
e.Run(fmt.Sprintf(":%d", port))
}