add address/advertise
This commit is contained in:
		| @@ -28,6 +28,7 @@ func (n *network) Close() error { | ||||
| func NewNetwork(opts ...Option) Network { | ||||
| 	options := Options{ | ||||
| 		Name:    DefaultName, | ||||
| 		Address: DefaultAddress, | ||||
| 		Client:  client.DefaultClient, | ||||
| 		Server:  server.DefaultServer, | ||||
| 		Proxy:   mucp.NewProxy(), | ||||
| @@ -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), | ||||
| 	) | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,6 @@ type Network interface { | ||||
|  | ||||
| var ( | ||||
| 	DefaultName    = "go.micro.network" | ||||
|  | ||||
| 	DefaultAddress = ":0" | ||||
| 	DefaultNetwork = NewNetwork() | ||||
| ) | ||||
|   | ||||
| @@ -10,7 +10,12 @@ import ( | ||||
| type Option func(*Options) | ||||
|  | ||||
| type Options struct { | ||||
| 	// 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 | ||||
| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user