@@ -13,16 +13,28 @@ import (
13
13
"os/signal"
14
14
"sync"
15
15
"syscall"
16
+ "time"
16
17
18
+ "{{.}}/api"
17
19
"{{.}}/config"
18
20
"{{.}}/server/xrpc"
19
21
"{{.}}/server/xweb"
20
22
"{{.}}/service"
23
+
24
+ "github.com/chenjie199234/Corelib/discovery"
25
+ "github.com/chenjie199234/Corelib/log"
21
26
)
22
27
23
28
func main() {
24
29
//stop watching config hot update
25
30
defer config.Close()
31
+ discoveryserververifydata := os.Getenv("DISCOVERY_SERVER_VERIFY_DATA")
32
+ if discoveryserververifydata != "" {
33
+ if e := discovery.NewDiscoveryClient(nil, api.Group, api.Name, []byte(discoveryserververifydata), nil); e != nil {
34
+ log.Error(e)
35
+ return
36
+ }
37
+ }
26
38
//start the whole business service
27
39
service.StartService()
28
40
//start low level net service
@@ -48,6 +60,33 @@ func main() {
48
60
}
49
61
wg.Done()
50
62
}()
63
+ stop := make(chan struct{}, 1)
64
+ go func() {
65
+ tmer := time.NewTimer(time.Millisecond * 200)
66
+ select {
67
+ case <-tmer.C:
68
+ rpcc := config.GetRpcConfig()
69
+ webc := config.GetHttpConfig()
70
+ regmsg := &discovery.RegMsg{}
71
+ if webc != nil {
72
+ if webc.HttpKeyFile != "" && webc.HttpCertFile != "" {
73
+ regmsg.WebScheme = "https"
74
+ } else {
75
+ regmsg.WebScheme = "http"
76
+ }
77
+ if webc.HttpPort != 0 {
78
+ regmsg.WebPort = int(webc.HttpPort)
79
+ }
80
+ }
81
+ if rpcc != nil {
82
+ if rpcc.RpcPort != 0 {
83
+ regmsg.RpcPort = int(rpcc.RpcPort)
84
+ }
85
+ }
86
+ discovery.RegisterSelf(regmsg)
87
+ case <-stop:
88
+ }
89
+ }()
51
90
signal.Notify(ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
52
91
<-ch
53
92
//stop the whole business service
0 commit comments