From 2d09e74b0e0010f96e88423765f18a33b765c41f Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 31 Jul 2019 15:35:51 +0100 Subject: [PATCH] add address/advertise --- network/default.go | 13 ++++++++----- network/network.go | 4 ++-- network/options.go | 29 ++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/network/default.go b/network/default.go index 13876e57..ff1d6c4b 100644 --- a/network/default.go +++ b/network/default.go @@ -27,11 +27,12 @@ func (n *network) Close() error { // NewNetwork returns a new network node func NewNetwork(opts ...Option) Network { options := Options{ - Name: DefaultName, - Client: client.DefaultClient, - Server: server.DefaultServer, - Proxy: mucp.NewProxy(), - Router: router.DefaultRouter, + Name: DefaultName, + Address: DefaultAddress, + Client: client.DefaultClient, + Server: server.DefaultServer, + Proxy: mucp.NewProxy(), + Router: router.DefaultRouter, } for _, o := range opts { @@ -41,6 +42,8 @@ func NewNetwork(opts ...Option) Network { // set the server name options.Server.Init( server.Name(options.Name), + server.Address(options.Address), + server.Advertise(options.Advertise), server.WithRouter(options.Proxy), ) diff --git a/network/network.go b/network/network.go index bf1a069b..a4e21ca9 100644 --- a/network/network.go +++ b/network/network.go @@ -12,7 +12,7 @@ type Network interface { } var ( - DefaultName = "go.micro.network" - + DefaultName = "go.micro.network" + DefaultAddress = ":0" DefaultNetwork = NewNetwork() ) diff --git a/network/options.go b/network/options.go index 2a211ea5..fbf41884 100644 --- a/network/options.go +++ b/network/options.go @@ -10,11 +10,16 @@ import ( type Option func(*Options) type Options struct { - Name string - Client client.Client - Server server.Server - Proxy proxy.Proxy - Router router.Router + // Name of the network + Name string + // Address of the node + Address string + // Advertise a different address to the network + Advertise string + Client client.Client + Server server.Server + Proxy proxy.Proxy + Router router.Router } // The network name @@ -24,6 +29,20 @@ func Name(n string) Option { } } +// The network address +func Address(a string) Option { + return func(o *Options) { + o.Address = a + } +} + +// The network advertise address +func Advertise(a string) Option { + return func(o *Options) { + o.Advertise = a + } +} + // The network client func Client(c client.Client) Option { return func(o *Options) {