2019-01-07 00:12:02 +03:00
|
|
|
// Package static provides a static resolver which returns the name/ip passed in without any change
|
|
|
|
package static
|
|
|
|
|
|
|
|
import (
|
2019-06-21 17:13:54 +03:00
|
|
|
"github.com/micro/go-micro/client/selector"
|
2019-06-21 19:20:41 +03:00
|
|
|
"github.com/micro/go-micro/registry"
|
2019-01-07 00:12:02 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// staticSelector is a static selector
|
|
|
|
type staticSelector struct {
|
|
|
|
opts selector.Options
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Init(opts ...selector.Option) error {
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&s.opts)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Options() selector.Options {
|
|
|
|
return s.opts
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
|
|
|
|
return func() (*registry.Node, error) {
|
|
|
|
return ®istry.Node{
|
|
|
|
Id: service,
|
2019-07-08 10:01:42 +03:00
|
|
|
Address: service,
|
2019-01-07 00:12:02 +03:00
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Mark(service string, node *registry.Node, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Reset(service string) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *staticSelector) String() string {
|
|
|
|
return "static"
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSelector(opts ...selector.Option) selector.Selector {
|
|
|
|
var options selector.Options
|
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return &staticSelector{
|
|
|
|
opts: options,
|
|
|
|
}
|
|
|
|
}
|