mirror of
https://github.com/go-micro/go-micro.git
synced 2025-08-10 21:52:01 +02:00
add advertising option
This commit is contained in:
@@ -13,6 +13,7 @@ type options struct {
|
||||
metadata map[string]string
|
||||
name string
|
||||
address string
|
||||
advertise string
|
||||
id string
|
||||
version string
|
||||
}
|
||||
@@ -71,6 +72,10 @@ func (o options) Address() string {
|
||||
return o.address
|
||||
}
|
||||
|
||||
func (o options) Advertise() string {
|
||||
return o.advertise
|
||||
}
|
||||
|
||||
func (o options) Metadata() map[string]string {
|
||||
return o.metadata
|
||||
}
|
||||
@@ -99,6 +104,12 @@ func Address(a string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func Advertise(a string) Option {
|
||||
return func(o *options) {
|
||||
o.advertise = a
|
||||
}
|
||||
}
|
||||
|
||||
func Broker(b broker.Broker) Option {
|
||||
return func(o *options) {
|
||||
o.broker = b
|
||||
|
@@ -114,10 +114,19 @@ func (s *rpcServer) Subscribe(sb Subscriber) error {
|
||||
func (s *rpcServer) Register() error {
|
||||
// parse address for host, port
|
||||
config := s.Config()
|
||||
var host string
|
||||
var advt, host string
|
||||
var port int
|
||||
|
||||
parts := strings.Split(config.Address(), ":")
|
||||
// check the advertise address first
|
||||
// if it exists then use it, otherwise
|
||||
// use the address
|
||||
if len(config.Advertise()) > 0 {
|
||||
advt = config.Advertise()
|
||||
} else {
|
||||
advt = config.Address()
|
||||
}
|
||||
|
||||
parts := strings.Split(advt, ":")
|
||||
if len(parts) > 1 {
|
||||
host = strings.Join(parts[:len(parts)-1], ":")
|
||||
port, _ = strconv.Atoi(parts[len(parts)-1])
|
||||
@@ -177,9 +186,19 @@ func (s *rpcServer) Register() error {
|
||||
|
||||
func (s *rpcServer) Deregister() error {
|
||||
config := s.Config()
|
||||
var host string
|
||||
var advt, host string
|
||||
var port int
|
||||
parts := strings.Split(config.Address(), ":")
|
||||
|
||||
// check the advertise address first
|
||||
// if it exists then use it, otherwise
|
||||
// use the address
|
||||
if len(config.Advertise()) > 0 {
|
||||
advt = config.Advertise()
|
||||
} else {
|
||||
advt = config.Address()
|
||||
}
|
||||
|
||||
parts := strings.Split(advt, ":")
|
||||
if len(parts) > 1 {
|
||||
host = strings.Join(parts[:len(parts)-1], ":")
|
||||
port, _ = strconv.Atoi(parts[len(parts)-1])
|
||||
|
Reference in New Issue
Block a user