add address/advertise
This commit is contained in:
parent
3e90d32f29
commit
2d09e74b0e
@ -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),
|
||||
)
|
||||
|
||||
|
@ -12,7 +12,7 @@ type Network interface {
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultName = "go.micro.network"
|
||||
|
||||
DefaultName = "go.micro.network"
|
||||
DefaultAddress = ":0"
|
||||
DefaultNetwork = NewNetwork()
|
||||
)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user