🎨 完善网关
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
李寻欢 2021-09-09 09:48:58 +08:00
parent cd2530afa4
commit 21950f5dbf
3 changed files with 7 additions and 8 deletions

View File

@ -39,7 +39,7 @@ func initNacos() {
if ips := utils.GetIps(); ips != nil { if ips := utils.GetIps(); ips != nil {
ip = ips[0] ip = ips[0]
} }
success, _ := client.RegisterInstance(vo.RegisterInstanceParam{ success, err := client.RegisterInstance(vo.RegisterInstanceParam{
Ip: ip, Ip: ip,
Port: config.AppInfo.Port, Port: config.AppInfo.Port,
Weight: 10, Weight: 10,
@ -50,7 +50,7 @@ func initNacos() {
}) })
core.Log.Debug("Nacos注册结果: %v", success) core.Log.Debug("Nacos注册结果: %v", success)
if !success { if !success {
core.Log.Panic("服务注册失败,退出程序") core.Log.Panic("服务注册失败,退出程序: %v", err.Error())
} }
// 打印所有服务 // 打印所有服务

View File

@ -3,6 +3,7 @@ package middleware
import ( import (
"fmt" "fmt"
gc "gateway/config" gc "gateway/config"
"gateway/core"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext" "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)) spCtx, err := opentracing.GlobalTracer().Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(c.Request.Header))
if err != nil { if err != nil {
core.Log.Error("Jaeger错误: %v", err.Error())
parentSpan = tracer.StartSpan(c.Request.URL.Path) parentSpan = tracer.StartSpan(c.Request.URL.Path)
defer parentSpan.Finish() defer parentSpan.Finish()
} else { } else {
@ -47,8 +49,6 @@ func OpenTracing() gin.HandlerFunc {
} }
} }
//var Tracer opentracing.Tracer
func NewJaegerTracer() (opentracing.Tracer, io.Closer) { func NewJaegerTracer() (opentracing.Tracer, io.Closer) {
cfg := &config.Configuration{ cfg := &config.Configuration{
Sampler: &config.SamplerConfig{ Sampler: &config.SamplerConfig{
@ -66,9 +66,10 @@ func NewJaegerTracer() (opentracing.Tracer, io.Closer) {
tracer, closer, err := cfg.NewTracer() tracer, closer, err := cfg.NewTracer()
if err != nil { if err != nil {
core.Log.Error("Jaeger连接失败: %v", err.Error())
return nil, nil return nil, nil
} }
core.Log.Debug("Jaeger连接成功")
opentracing.SetGlobalTracer(tracer) opentracing.SetGlobalTracer(tracer)
//Tracer = tracer
return tracer, closer return tracer, closer
} }

View File

@ -1,7 +1,6 @@
package utils package utils
import ( import (
"fmt"
"net" "net"
) )
@ -17,11 +16,10 @@ func GetIps() []string {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil { if ipnet.IP.To4() != nil {
ip := ipnet.IP.String() ip := ipnet.IP.String()
fmt.Println(ip)
ips = append(ips, ip) ips = append(ips, ip)
} }
} }
} }
//ipStr := strings.Join(aaaa, ",") //ipStr := strings.Join(ips, ",")
return ips return ips
} }