use helper
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
4209736cb8
commit
ff05219e28
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/golang/protobuf v1.4.2
|
github.com/golang/protobuf v1.4.2
|
||||||
github.com/google/go-cmp v0.5.1 // indirect
|
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-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/net v0.0.0-20200904194848-62affa334b73
|
||||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect
|
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect
|
||||||
golang.org/x/text v0.3.3 // indirect
|
golang.org/x/text v0.3.3 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -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-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.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.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.20201009135158-2fc47782cf47 h1:3d/HgT7Iq/UIw5OGyzfUeZPJwydhBohh9shyGJH14EA=
|
||||||
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/go.mod h1:aL+8VhSXpx0SuEeXPOWUo5BgS7kyvWYobeXFay90UUM=
|
||||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
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/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
|
50
grpc.go
50
grpc.go
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/util/backoff"
|
"github.com/unistack-org/micro/v3/util/backoff"
|
||||||
mgrpc "github.com/unistack-org/micro/v3/util/grpc"
|
mgrpc "github.com/unistack-org/micro/v3/util/grpc"
|
||||||
mnet "github.com/unistack-org/micro/v3/util/net"
|
mnet "github.com/unistack-org/micro/v3/util/net"
|
||||||
|
regutil "github.com/unistack-org/micro/v3/util/registry"
|
||||||
"golang.org/x/net/netutil"
|
"golang.org/x/net/netutil"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
@ -718,49 +719,13 @@ func (g *grpcServer) Register() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var advt, host, port string
|
var service *registry.Service
|
||||||
var cacheService bool
|
var cacheService bool
|
||||||
|
|
||||||
advt = config.Advertise
|
service, err = regutil.NewService(g)
|
||||||
|
|
||||||
if cnt := strings.Count(advt, ":"); cnt >= 1 {
|
|
||||||
// ipv6 address in format [host]:port or ipv4 host:port
|
|
||||||
host, port, err = net.SplitHostPort(advt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 := ®istry.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()
|
g.RLock()
|
||||||
// Maps are ordered randomly, sort the keys for consistency
|
// Maps are ordered randomly, sort the keys for consistency
|
||||||
@ -794,12 +759,7 @@ func (g *grpcServer) Register() error {
|
|||||||
}
|
}
|
||||||
g.RUnlock()
|
g.RUnlock()
|
||||||
|
|
||||||
service := ®istry.Service{
|
service.Endpoints = endpoints
|
||||||
Name: config.Name,
|
|
||||||
Version: config.Version,
|
|
||||||
Nodes: []*registry.Node{node},
|
|
||||||
Endpoints: endpoints,
|
|
||||||
}
|
|
||||||
|
|
||||||
g.RLock()
|
g.RLock()
|
||||||
registered := g.registered
|
registered := g.registered
|
||||||
@ -807,7 +767,7 @@ func (g *grpcServer) Register() error {
|
|||||||
|
|
||||||
if !registered {
|
if !registered {
|
||||||
if logger.V(logger.InfoLevel) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user