zhangqian
2023-09-11 72bf0888a07c4fb321e96869acdf88b2e381c9e8
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
package main
 
import (
    "net/http"
    "os"
    "os/signal"
    "syscall"
    "time"
    "wms/conf"
    "wms/constvar"
    "wms/models"
    "wms/pkg/logx"
    "wms/router"
)
 
func main() {
    // 读取配置
    if err := conf.Init(); err != nil {
        logx.Errorf("config init error! ", err.Error())
        return
    }
 
    // 日志初始化
    logx.Init(*conf.LogConf)
    defer logx.Sync()
 
    // 数据库初始化
    if err := models.Init(); err != nil {
        logx.Errorf("db init error! ", err.Error())
        return
    }
 
    // 启动APS RPC服务
    //safe.Go(service.StartAPServer)
 
    go shutdown()
    logx.Infof("aps-server start serve...")
    server := &http.Server{
        Addr:         ":" + conf.WebConf.Port,
        Handler:      router.NewRouter(),
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 5 * time.Second,
    }
 
    logx.Error(server.ListenAndServe().Error())
}
 
func shutdown() {
    quit := make(chan os.Signal, 1)
    signal.Notify(quit, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM)
    <-quit
 
    _ = constvar.GrpcClient.Close()
    logx.Infof("aps-server exited...")
    os.Exit(0)
}