-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 1.23 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
package main
import (
"context"
"embed"
"flag"
"path/filepath"
"code.gopub.tech/gbt/common/conf"
"code.gopub.tech/gbt/webs"
"code.gopub.tech/logs"
"github.com/gin-gonic/gin"
"github.com/youthlin/t"
)
//go:embed resource/lang
var language embed.FS
var ctx = context.Background()
var dir = flag.String("data", ".", "data dir")
func main() {
MustInit() // 初始化
startWeb() // 开启服务
}
func MustInit() {
flag.Parse()
dir := *dir
abs, err := filepath.Abs(dir)
if err != nil {
logs.Panic(ctx, "failed to get abs path of %v: %+v", dir, err)
}
// logs 日志输出控制台、文件
logs.SetDefault(logs.NewLogger(logs.CombineHandlers(
logs.NewHandler(), // console
logs.NewHandler(logs.WithFile(filepath.Join(abs, "logs", "app.log"))), // log file
)))
logs.Info(ctx, "use data dir %q. starting app...", abs)
if err = conf.ReadConfig(dir); err != nil {
logs.Panic(ctx, "failed to read/create config file: %+v", err)
}
webs.InitI18n(language)
logs.Info(ctx, t.T("Hello, World"))
logs.Debug(ctx, t.N("I have One appale.", "I've %v apples.", 2, 2))
}
func startWeb() {
r := gin.Default()
register(r)
addr := conf.AppConf.Addr
logs.Info(ctx, t.T("app run on %s", addr))
logs.Info(ctx, "run: %+v", r.Run(addr))
}