diff --git a/resource/consul/consul.go b/resource/consul/consul.go index cee7db1895c870ac629015cfbbe0abfeb2ceda04..a9cf9411d98eeb97216b6469eb37b38a8e31e3e2 100644 --- a/resource/consul/consul.go +++ b/resource/consul/consul.go @@ -29,11 +29,13 @@ 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 - } + go func() { + 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 {