add address/advertise
This commit is contained in:
		| @@ -28,6 +28,7 @@ func (n *network) Close() error { | |||||||
| func NewNetwork(opts ...Option) Network { | func NewNetwork(opts ...Option) Network { | ||||||
| 	options := Options{ | 	options := Options{ | ||||||
| 		Name:    DefaultName, | 		Name:    DefaultName, | ||||||
|  | 		Address: DefaultAddress, | ||||||
| 		Client:  client.DefaultClient, | 		Client:  client.DefaultClient, | ||||||
| 		Server:  server.DefaultServer, | 		Server:  server.DefaultServer, | ||||||
| 		Proxy:   mucp.NewProxy(), | 		Proxy:   mucp.NewProxy(), | ||||||
| @@ -41,6 +42,8 @@ func NewNetwork(opts ...Option) Network { | |||||||
| 	// set the server name | 	// set the server name | ||||||
| 	options.Server.Init( | 	options.Server.Init( | ||||||
| 		server.Name(options.Name), | 		server.Name(options.Name), | ||||||
|  | 		server.Address(options.Address), | ||||||
|  | 		server.Advertise(options.Advertise), | ||||||
| 		server.WithRouter(options.Proxy), | 		server.WithRouter(options.Proxy), | ||||||
| 	) | 	) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,6 +13,6 @@ type Network interface { | |||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	DefaultName    = "go.micro.network" | 	DefaultName    = "go.micro.network" | ||||||
|  | 	DefaultAddress = ":0" | ||||||
| 	DefaultNetwork = NewNetwork() | 	DefaultNetwork = NewNetwork() | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -10,7 +10,12 @@ import ( | |||||||
| type Option func(*Options) | type Option func(*Options) | ||||||
|  |  | ||||||
| type Options struct { | type Options struct { | ||||||
|  | 	// Name of the network | ||||||
| 	Name string | 	Name string | ||||||
|  | 	// Address of the node | ||||||
|  | 	Address string | ||||||
|  | 	// Advertise a different address to the network | ||||||
|  | 	Advertise string | ||||||
| 	Client    client.Client | 	Client    client.Client | ||||||
| 	Server    server.Server | 	Server    server.Server | ||||||
| 	Proxy     proxy.Proxy | 	Proxy     proxy.Proxy | ||||||
| @@ -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 | // The network client | ||||||
| func Client(c client.Client) Option { | func Client(c client.Client) Option { | ||||||
| 	return func(o *Options) { | 	return func(o *Options) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user