-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
115 lines (91 loc) · 2.42 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/gin-gonic/gin/binding"
"go-cygnus/apis"
"go-cygnus/clients"
"go-cygnus/models"
"go-cygnus/utils/db"
"go-cygnus/utils/logging"
"go-cygnus/utils/validators"
// docs is generated by Swag CLI, you have to import it.
_ "go-cygnus/docs"
)
var (
Version string
GoVersion string
webServer bool
)
func init() {
flag.BoolVar(&webServer, "webServer", true, "start web server")
}
// @title Captain API Documents
// @version 1.0
// @BasePath /v1
func main() {
flag.Parse()
printBanner()
// Initialize
defer logging.Finalize()
// redis init
// gorm migration
db.Init()
models.SyncDB()
// module init
clients.Init()
clients.SetLogger(logging.GetLogger("restclient").WithContext(context.Background()))
// system configs
//utils.SystemInit()
//kafka.InitSharedProducer()
// k8s init and
//k8s.Init()
// Sentry
// To initialize Sentry's handler, you need to initialize Sentry itself beforehand
//monitor.SentryInit()
// Web server
if webServer {
apis.WebAPIServer.Run(":8080")
}
// Upgrade validator from v8 to v9 globally
binding.Validator = new(validators.DefaultValidator)
// Task runner
// run forever & shutdown part
// Create a channel to receive notifications as go
// signal notification works by sending `os.Signal`
// values on a channel
quit := make(chan os.Signal, 1)
// `signal.Notify` registers the given channel to
// receive notifications of the specified signals.
signal.Notify(quit, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
sig := <-quit
logging.GetLogger("root").Infof("receive %s signal, quiting...", sig)
// The program will wait here until it gets the
// expected signal and then gracefully shutdown
// server.
if webServer {
ctxWeb := apis.WebAPIServer.Shutdown()
<-ctxWeb.Done()
}
}
func printBanner() {
const BANNER = `
_____ __ __ _______ __ __ __ __ _______
/ ____|\ \ / / / ______| | \ | | | | | | / ______|
| | \ \_/ / | | ___ | \| | | | | | | |_____
| | \ / | | |__ \ | |\ | | | | | \_____ \
| |____ | | | |___| | | | \ | | \__/ | _____| |
\_____/ |_| \_______/ |__| \__| \______/ |_______/
An expand go web framework
Version: %s
Go: %s
`
l := logging.GetLogger("root")
if _, err := fmt.Fprintf(l.Logger.Out, BANNER, Version, GoVersion); err != nil {
l.Infof("Print banner error")
}
}