-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 1.08 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
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"time"
"github.com/yiwen-ai/auth-api/src/api"
"github.com/yiwen-ai/auth-api/src/conf"
"github.com/yiwen-ai/auth-api/src/logging"
)
var help = flag.Bool("help", false, "show help info")
var version = flag.Bool("version", false, "show version info")
func main() {
flag.Parse()
if *help || *version {
data, _ := json.Marshal(api.GetVersion())
fmt.Println(string(data))
os.Exit(0)
}
app := api.NewApp()
host := "http://" + conf.Config.Server.Addr
logging.Infof("%s@%s start on %s %s", conf.AppName, conf.AppVersion, conf.Config.Env, host)
err := app.ListenWithContext(conf.Config.GlobalSignal, conf.Config.Server.Addr)
logging.Warningf("%s@%s http server closed: %v", conf.AppName, conf.AppVersion, err)
ctx := conf.Config.GlobalShutdown
for {
if conf.Config.JobsIdle() {
logging.Infof("%s@%s shutdown: OK", conf.AppName, conf.AppVersion)
return
}
select {
case <-ctx.Done():
logging.Errf("%s@%s shutdown: %v", conf.AppName, conf.AppVersion, ctx.Err())
return
case <-time.After(time.Second):
}
}
}