-
Notifications
You must be signed in to change notification settings - Fork 46
/
main.go
52 lines (42 loc) · 1.19 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
package main
import (
"flag"
"fmt"
"os"
"github.com/rs/zerolog/log"
"github.com/fakeyanss/jt808-server-go/internal/api"
"github.com/fakeyanss/jt808-server-go/internal/config"
"github.com/fakeyanss/jt808-server-go/internal/server"
"github.com/fakeyanss/jt808-server-go/pkg/logger"
"github.com/fakeyanss/jt808-server-go/pkg/routines"
)
func main() {
routines.Recover()
var cfgPath string
flag.StringVar(&cfgPath, "c", config.DefaultServConfKey, "config file path")
flag.Parse()
fmt.Printf("Start with configuration %v\n", cfgPath)
cfg := config.Load(cfgPath)
logConfig := cfg.ParseLogConf()
log.Logger = *logger.Configure(logConfig).Logger
if cfg.Server.Banner.Enable {
bannerBytes, err := os.ReadFile(cfg.Server.Banner.BannerPath)
var banner string
if err != nil {
banner = config.BannerText
} else {
banner = string(bannerBytes)
}
fmt.Println(banner)
}
serv := server.NewTCPServer()
addr := ":" + cfg.Server.Port.TCPPort
err := serv.Listen(addr)
if err != nil {
log.Error().Err(err).Str("addr", addr).Msg("Fail to listen tcp addr")
os.Exit(1)
}
routines.GoSafe(func() { serv.Start() })
routines.GoSafe(func() { api.Run(serv, cfg) })
select {} // block here
}