You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
1019 B

package selector
import (
"git.diulo.com/mogfee/kit/registry"
"strconv"
)
type DefaultNode struct {
scheme string
address string
weight *int64
version string
name string
metadata map[string]string
}
func (d *DefaultNode) Scheme() string {
return d.scheme
}
func (d *DefaultNode) Address() string {
return d.address
}
func (d *DefaultNode) ServiceName() string {
return d.name
}
func (d *DefaultNode) InitialWeight() *int64 {
return d.weight
}
func (d *DefaultNode) Version() string {
return d.version
}
func (d *DefaultNode) Metadata() map[string]string {
return d.metadata
}
func NewNode(scheme string, address string, ins *registry.ServiceInstance) Node {
node := &DefaultNode{
scheme: scheme,
address: address,
}
if ins != nil {
node.name = ins.Name
node.version = ins.Version
node.metadata = ins.Metadata
if str, ok := ins.Metadata["weight"]; ok {
if weight, err := strconv.ParseInt(str, 10, 64); err == nil {
node.weight = &weight
}
}
}
return node
}