-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
81 lines (67 loc) · 1.77 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
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"net/http"
"github.com/singcl/gin-taro-api/configs"
"github.com/singcl/gin-taro-api/internal/router"
"github.com/singcl/gin-taro-api/pkg/env"
"github.com/singcl/gin-taro-api/pkg/logger"
"github.com/singcl/gin-taro-api/pkg/shutdown"
"github.com/singcl/gin-taro-api/pkg/timeutil"
"go.uber.org/zap"
)
// @title swagger 接口文档
// @version 0.0
// @description
// @contact.name
// @contact.url
// @contact.email
// @license.name MIT
// @license.url https://github.com/singcl
// @securityDefinitions.apikey LoginToken
// @in header
// @name token
// @BasePath /
func main() {
// 初始化 access logger
accessLogger, err := logger.NewJSONLogger(
logger.WithDisableConsole(),
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
logger.WithTimeLayout(timeutil.CSTLayout),
logger.WithFileP(configs.ProjectAccessLogFile),
)
if err != nil {
panic(err)
}
// 初始化 cron logger
cronLogger, err := logger.NewJSONLogger(
logger.WithDisableConsole(),
logger.WithField("domain", fmt.Sprintf("%s[%s]", configs.ProjectName, env.Active().Value())),
logger.WithTimeLayout(timeutil.CSTLayout),
logger.WithFileP(configs.ProjectCronLogFile),
)
if err != nil {
panic(err)
}
defer func() {
_ = accessLogger.Sync()
_ = cronLogger.Sync()
}()
// 初始化 HTTP 服务
s, err := router.NewHTTPServer(accessLogger, cronLogger)
if err != nil {
panic(err)
}
server := &http.Server{
Addr: configs.ProjectPort,
Handler: s.Kiko,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
// logger
accessLogger.Fatal("http server startup err", zap.Error(err))
}
}()
//
shutdown.NewHook().Close()
}