Commit 483fd7af authored by hujiebin's avatar hujiebin

refact:调整注册时间

parent 765be39a
......@@ -27,6 +27,14 @@ func consulCheck(w http.ResponseWriter, r *http.Request) {
}
func register(port int, retry bool) {
checkPort := port + 1000
if !retry {
http.HandleFunc("/check", consulCheck)
if err := http.ListenAndServe(fmt.Sprintf(":%d", checkPort), nil); err != nil {
mylogrus.MyLog.Warnf("check server error :%v ", err)
return
}
}
client, err := api.NewClient(api.DefaultConfig()) //非默认情况下需要设置实际的参数
if err != nil {
mylogrus.MyLog.Errorf("RegisterToConsul Fail:%v", err)
......@@ -37,7 +45,6 @@ func register(port int, retry bool) {
return
}
mylogrus.MyLog.Infof("RegisterToConsul:%v-%v", client, err)
checkPort := port + 1000
registration := new(api.AgentServiceRegistration)
hostName, _ := os.Hostname()
registration.ID = fmt.Sprintf("%s-%s", RegisterName, hostName)
......@@ -65,13 +72,6 @@ func register(port int, retry bool) {
mylogrus.MyLog.Errorf("register server error :%v ", err)
return
}
if !retry {
http.HandleFunc("/check", consulCheck)
if err = http.ListenAndServe(fmt.Sprintf(":%d", checkPort), nil); err != nil {
mylogrus.MyLog.Warnf("check server error :%v ", err)
return
}
}
}
// 自愈检查
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment