use helper

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-10-09 17:42:55 +03:00
parent 4209736cb8
commit ff05219e28
3 changed files with 8 additions and 48 deletions

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/golang/protobuf v1.4.2
github.com/google/go-cmp v0.5.1 // indirect
github.com/unistack-org/micro-codec-bytes v0.0.0-20200828083432-4e49e953d844
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009132147-336868ed0d8d
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009135158-2fc47782cf47
golang.org/x/net v0.0.0-20200904194848-62affa334b73
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect
golang.org/x/text v0.3.3 // indirect

4
go.sum
View File

@ -265,8 +265,8 @@ github.com/unistack-org/micro-config-cmd v0.0.0-20200920140133-0853deb2e5dc/go.m
github.com/unistack-org/micro/v3 v3.0.0-20200827083227-aa99378adc6e/go.mod h1:rPQbnry3nboAnMczj8B1Gzlcyv/HYoMZLgd3/3nttJ4=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200909210629-caec730248b1/go.mod h1:mmqHR9WelHUXqg2mELjsQ+FJHcWs6mNmXg+wEYO2T3c=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20200920135754-1cbd1d2bad83/go.mod h1:HUzMG4Mcy97958VxWTg8zuazZgwQ/aoLZ8wtBVONwRE=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009132147-336868ed0d8d h1:LcDlJMSPibasCxm8WNWM92bz+7NFX8StPfM+4u/fme8=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009132147-336868ed0d8d/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009135158-2fc47782cf47 h1:3d/HgT7Iq/UIw5OGyzfUeZPJwydhBohh9shyGJH14EA=
github.com/unistack-org/micro/v3 v3.0.0-gamma.0.20201009135158-2fc47782cf47/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=

50
grpc.go
View File

@ -25,6 +25,7 @@ import (
"github.com/unistack-org/micro/v3/util/backoff"
mgrpc "github.com/unistack-org/micro/v3/util/grpc"
mnet "github.com/unistack-org/micro/v3/util/net"
regutil "github.com/unistack-org/micro/v3/util/registry"
"golang.org/x/net/netutil"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@ -718,49 +719,13 @@ func (g *grpcServer) Register() error {
}
var err error
var advt, host, port string
var service *registry.Service
var cacheService bool
advt = config.Advertise
if cnt := strings.Count(advt, ":"); cnt >= 1 {
// ipv6 address in format [host]:port or ipv4 host:port
host, port, err = net.SplitHostPort(advt)
service, err = regutil.NewService(g)
if err != nil {
return err
}
} else {
host = advt
}
if ip := net.ParseIP(host); ip != nil {
cacheService = true
}
addr, err := addr.Extract(host)
if err != nil {
return err
}
// make copy of metadata
md := meta.Copy(config.Metadata)
// register service
node := &registry.Node{
Id: config.Name + "-" + config.Id,
Address: mnet.HostPort(addr, port),
Metadata: md,
}
if node.Metadata == nil {
node.Metadata = make(map[string]string, 5)
}
node.Metadata["broker"] = config.Broker.String()
node.Metadata["registry"] = config.Registry.String()
node.Metadata["server"] = g.String()
node.Metadata["transport"] = g.String()
node.Metadata["protocol"] = "grpc"
g.RLock()
// Maps are ordered randomly, sort the keys for consistency
@ -794,12 +759,7 @@ func (g *grpcServer) Register() error {
}
g.RUnlock()
service := &registry.Service{
Name: config.Name,
Version: config.Version,
Nodes: []*registry.Node{node},
Endpoints: endpoints,
}
service.Endpoints = endpoints
g.RLock()
registered := g.registered
@ -807,7 +767,7 @@ func (g *grpcServer) Register() error {
if !registered {
if logger.V(logger.InfoLevel) {
logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), service.Nodes[0].Id)
}
}