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
|
// NewNetwork returns a new network node
|
||||||
func NewNetwork(opts ...Option) Network {
|
func NewNetwork(opts ...Option) Network {
|
||||||
options := Options{
|
options := Options{
|
||||||
Name: DefaultName,
|
Name: DefaultName,
|
||||||
Client: client.DefaultClient,
|
Address: DefaultAddress,
|
||||||
Server: server.DefaultServer,
|
Client: client.DefaultClient,
|
||||||
Proxy: mucp.NewProxy(),
|
Server: server.DefaultServer,
|
||||||
Router: router.DefaultRouter,
|
Proxy: mucp.NewProxy(),
|
||||||
|
Router: router.DefaultRouter,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
@ -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),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ type Network interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DefaultName = "go.micro.network"
|
DefaultName = "go.micro.network"
|
||||||
|
DefaultAddress = ":0"
|
||||||
DefaultNetwork = NewNetwork()
|
DefaultNetwork = NewNetwork()
|
||||||
)
|
)
|
||||||
|
@ -10,11 +10,16 @@ import (
|
|||||||
type Option func(*Options)
|
type Option func(*Options)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Name string
|
// Name of the network
|
||||||
Client client.Client
|
Name string
|
||||||
Server server.Server
|
// Address of the node
|
||||||
Proxy proxy.Proxy
|
Address string
|
||||||
Router router.Router
|
// Advertise a different address to the network
|
||||||
|
Advertise string
|
||||||
|
Client client.Client
|
||||||
|
Server server.Server
|
||||||
|
Proxy proxy.Proxy
|
||||||
|
Router router.Router
|
||||||
}
|
}
|
||||||
|
|
||||||
// The network name
|
// 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
|
// The network client
|
||||||
func Client(c client.Client) Option {
|
func Client(c client.Client) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user