gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/client/selector/static/static.go (about)

     1  // Package static provides a static resolver which returns the name/ip passed in without any change
     2  package static
     3  
     4  import (
     5  	"gitee.com/liuxuezhan/go-micro-v1.18.0/client/selector"
     6  	"gitee.com/liuxuezhan/go-micro-v1.18.0/registry"
     7  )
     8  
     9  // staticSelector is a static selector
    10  type staticSelector struct {
    11  	opts selector.Options
    12  }
    13  
    14  func (s *staticSelector) Init(opts ...selector.Option) error {
    15  	for _, o := range opts {
    16  		o(&s.opts)
    17  	}
    18  	return nil
    19  }
    20  
    21  func (s *staticSelector) Options() selector.Options {
    22  	return s.opts
    23  }
    24  
    25  func (s *staticSelector) Select(service string, opts ...selector.SelectOption) (selector.Next, error) {
    26  	return func() (*registry.Node, error) {
    27  		return &registry.Node{
    28  			Id:      service,
    29  			Address: service,
    30  		}, nil
    31  	}, nil
    32  }
    33  
    34  func (s *staticSelector) Mark(service string, node *registry.Node, err error) {
    35  	return
    36  }
    37  
    38  func (s *staticSelector) Reset(service string) {
    39  	return
    40  }
    41  
    42  func (s *staticSelector) Close() error {
    43  	return nil
    44  }
    45  
    46  func (s *staticSelector) String() string {
    47  	return "static"
    48  }
    49  
    50  func NewSelector(opts ...selector.Option) selector.Selector {
    51  	var options selector.Options
    52  	for _, o := range opts {
    53  		o(&options)
    54  	}
    55  	return &staticSelector{
    56  		opts: options,
    57  	}
    58  }