liujiandao
2023-10-11 34ef7217a034599217a7fdd1e28e1ae6910e1b4b
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
package main
 
import (
    v1 "aps_crm/api/v1"
    "aps_crm/conf"
    "aps_crm/initialize"
    "aps_crm/model"
    "aps_crm/pkg/logx"
    "aps_crm/router"
    "aps_crm/service"
    "fmt"
    "net/http"
    "os"
    "os/signal"
    "syscall"
    "time"
)
 
func main() {
    logx.Init(conf.Conf.Log)
    defer logx.Sync()
 
    //cont := service.NewContainer(service.Type_Container_Docker)
    //err := cont.Init("123456")
    //if err != nil {
    //    logx.Errorf("NewContainer Init err:%v", err)
    //    return
    //}
 
    if err := model.Init(); err != nil {
        logx.Errorf("model Init err:%v", err)
        return
    }
 
    if err := initialize.Init(); err != nil {
        logx.Errorf("initialize Init err:%v", err)
        return
    }
 
    go shutdown()
    logx.Infof("aps-crm start serve...")
    server := &http.Server{
        Addr:         fmt.Sprintf(":%d", conf.Conf.System.Port),
        Handler:      router.InitRouter(),
        ReadTimeout:  5 * time.Second,
        WriteTimeout: 5 * time.Second,
    }
 
    go v1.InitProductServiceConn()
    go service.InitUserConn()
    go v1.InitCodeServiceConn()
 
    //c := cron.New()
    //c.AddFunc("@every 15s", service.SyncUserInfo) // 每15秒同步一次
    //c.Start()
 
    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
 
    v1.CloseProductServiceConn()
    service.CloseUserConn()
    v1.CloseCodeServiceConn()
 
    logx.Infof("aps-crm exited...")
    os.Exit(0)
}