From 2b4fe41299f0e08c0ed90e21af0518f227f6ed30 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 24 Mar 2023 10:25:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9AhttpListen=E4=BC=9A=E9=98=BB?= =?UTF-8?q?=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resource/consul/consul.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resource/consul/consul.go b/resource/consul/consul.go index cee7db1..a9cf941 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 { -- 2.22.0