diff --git a/network/default.go b/network/default.go index 626f9281..c8ab8fc2 100644 --- a/network/default.go +++ b/network/default.go @@ -18,6 +18,9 @@ type network struct { // name of the network name string + // network address used where one is specified + address string + // transport transport transport.Transport } @@ -34,15 +37,16 @@ type listener struct { } func (n *network) Create() (*Node, error) { - ip, err := addr.Extract("") + ip, err := addr.Extract(n.address) if err != nil { return nil, err } return &Node{ Id: fmt.Sprintf("%s-%s", n.name, uuid.New().String()), Address: ip, + Network: n.Name(), Metadata: map[string]string{ - "network": n.Name(), + "network": n.String(), "transport": n.transport.String(), }, }, nil @@ -140,6 +144,12 @@ func newNetwork(opts ...options.Option) *network { net.name = name.(string) } + // get network name + address, ok := options.Values().Get("network.address") + if ok { + net.address = address.(string) + } + // get network transport t, ok := options.Values().Get("network.transport") if ok { diff --git a/network/network.go b/network/network.go index 3198bf3f..b7f7357c 100644 --- a/network/network.go +++ b/network/network.go @@ -3,6 +3,7 @@ package network import ( "github.com/micro/go-micro/config/options" + "github.com/micro/go-micro/network/transport" ) // Network defines a network interface. The network is a single @@ -25,6 +26,7 @@ type Network interface { type Node struct { Id string Address string + Network string Metadata map[string]string } @@ -69,3 +71,18 @@ var ( func NewNetwork(opts ...options.Option) Network { return newNetwork(opts...) } + +// Name sets the network name +func Name(n string) options.Option { + return options.WithValue("network.name", n) +} + +// Address sets the network address +func Address(a string) options.Option { + return options.WithValue("network.address", a) +} + +// Transport sets the network transport +func Transport(t transport.Transport) options.Option { + return options.WithValue("network.transport", t) +}