github.com/btccom/go-micro/v2@v2.9.3/api/router/options.go (about)

     1  package router
     2  
     3  import (
     4  	"github.com/btccom/go-micro/v2/api/resolver"
     5  	"github.com/btccom/go-micro/v2/api/resolver/vpath"
     6  	"github.com/btccom/go-micro/v2/registry"
     7  )
     8  
     9  type Options struct {
    10  	Handler  string
    11  	Registry registry.Registry
    12  	Resolver resolver.Resolver
    13  }
    14  
    15  type Option func(o *Options)
    16  
    17  func NewOptions(opts ...Option) Options {
    18  	options := Options{
    19  		Handler:  "meta",
    20  		Registry: registry.DefaultRegistry,
    21  	}
    22  
    23  	for _, o := range opts {
    24  		o(&options)
    25  	}
    26  
    27  	if options.Resolver == nil {
    28  		options.Resolver = vpath.NewResolver(
    29  			resolver.WithHandler(options.Handler),
    30  		)
    31  	}
    32  
    33  	return options
    34  }
    35  
    36  func WithHandler(h string) Option {
    37  	return func(o *Options) {
    38  		o.Handler = h
    39  	}
    40  }
    41  
    42  func WithRegistry(r registry.Registry) Option {
    43  	return func(o *Options) {
    44  		o.Registry = r
    45  	}
    46  }
    47  
    48  func WithResolver(r resolver.Resolver) Option {
    49  	return func(o *Options) {
    50  		o.Resolver = r
    51  	}
    52  }