From 21950f5dbfb7a223df66db6fe697c9d8ac25ee00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Thu, 9 Sep 2021 09:48:58 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=AE=8C=E5=96=84=E7=BD=91=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initialization/nacos.go | 4 ++-- middleware/jaeger.go | 7 ++++--- utils/ip_utils.go | 4 +--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/initialization/nacos.go b/initialization/nacos.go index 8c44cc0..eb31f67 100644 --- a/initialization/nacos.go +++ b/initialization/nacos.go @@ -39,7 +39,7 @@ func initNacos() { if ips := utils.GetIps(); ips != nil { ip = ips[0] } - success, _ := client.RegisterInstance(vo.RegisterInstanceParam{ + success, err := client.RegisterInstance(vo.RegisterInstanceParam{ Ip: ip, Port: config.AppInfo.Port, Weight: 10, @@ -50,7 +50,7 @@ func initNacos() { }) core.Log.Debug("Nacos注册结果: %v", success) if !success { - core.Log.Panic("服务注册失败,退出程序") + core.Log.Panic("服务注册失败,退出程序: %v", err.Error()) } // 打印所有服务 diff --git a/middleware/jaeger.go b/middleware/jaeger.go index 4c1edcd..f35c2b5 100644 --- a/middleware/jaeger.go +++ b/middleware/jaeger.go @@ -3,6 +3,7 @@ package middleware import ( "fmt" gc "gateway/config" + "gateway/core" "github.com/gin-gonic/gin" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" @@ -20,6 +21,7 @@ func OpenTracing() gin.HandlerFunc { spCtx, err := opentracing.GlobalTracer().Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(c.Request.Header)) if err != nil { + core.Log.Error("Jaeger错误: %v", err.Error()) parentSpan = tracer.StartSpan(c.Request.URL.Path) defer parentSpan.Finish() } else { @@ -47,8 +49,6 @@ func OpenTracing() gin.HandlerFunc { } } -//var Tracer opentracing.Tracer - func NewJaegerTracer() (opentracing.Tracer, io.Closer) { cfg := &config.Configuration{ Sampler: &config.SamplerConfig{ @@ -66,9 +66,10 @@ func NewJaegerTracer() (opentracing.Tracer, io.Closer) { tracer, closer, err := cfg.NewTracer() if err != nil { + core.Log.Error("Jaeger连接失败: %v", err.Error()) return nil, nil } + core.Log.Debug("Jaeger连接成功") opentracing.SetGlobalTracer(tracer) - //Tracer = tracer return tracer, closer } diff --git a/utils/ip_utils.go b/utils/ip_utils.go index 242ee80..76bd7ae 100644 --- a/utils/ip_utils.go +++ b/utils/ip_utils.go @@ -1,7 +1,6 @@ package utils import ( - "fmt" "net" ) @@ -17,11 +16,10 @@ func GetIps() []string { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet.IP.To4() != nil { ip := ipnet.IP.String() - fmt.Println(ip) ips = append(ips, ip) } } } - //ipStr := strings.Join(aaaa, ",") + //ipStr := strings.Join(ips, ",") return ips }