-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (50 loc) · 1.33 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
package main
import (
"github.com/aurorachat/auth/auth"
"github.com/aurorachat/backend/chat"
"github.com/aurorachat/backend/config"
"github.com/gin-gonic/gin"
sloggin "github.com/samber/slog-gin"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"log/slog"
"os"
"os/signal"
"syscall"
)
func main() {
byeSignal := make(chan os.Signal)
signal.Notify(byeSignal, syscall.SIGINT, syscall.SIGTERM)
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
router := gin.New()
router.Use(sloggin.New(logger))
router.Use(gin.Recovery())
db, err := gorm.Open(postgres.New(postgres.Config{
DSN: config.GetPostgresDSN(),
PreferSimpleProtocol: true, // according to the docs gorm already does all the things
}), &gorm.Config{})
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
authEngine, err := auth.NewEngine(auth.NewOptions(authHandler(), db, router, []byte(config.GetAuthSecretKey())))
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
_ = authEngine.SetUserActivated(1, true)
chat.Initialize(router)
go func() {
err = router.Run(config.GetListenHost())
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
}()
sig := <-byeSignal
logger.Info("Shutting the application down", "signal", sig.String())
}
func authHandler() auth.Handler {
return func(ctx *auth.ActionContext) {
}
}