github.com/annwntech/go-micro/v2@v2.9.5/config/cmd/options.go (about)

     1  package cmd
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/annwntech/go-micro/v2/auth"
     7  	"github.com/annwntech/go-micro/v2/broker"
     8  	"github.com/annwntech/go-micro/v2/client"
     9  	"github.com/annwntech/go-micro/v2/client/selector"
    10  	"github.com/annwntech/go-micro/v2/config"
    11  	"github.com/annwntech/go-micro/v2/debug/profile"
    12  	"github.com/annwntech/go-micro/v2/debug/trace"
    13  	"github.com/annwntech/go-micro/v2/registry"
    14  	"github.com/annwntech/go-micro/v2/runtime"
    15  	"github.com/annwntech/go-micro/v2/server"
    16  	"github.com/annwntech/go-micro/v2/store"
    17  	"github.com/annwntech/go-micro/v2/transport"
    18  )
    19  
    20  type Options struct {
    21  	// For the Command Line itself
    22  	Name        string
    23  	Description string
    24  	Version     string
    25  
    26  	// We need pointers to things so we can swap them out if needed.
    27  	Broker    *broker.Broker
    28  	Registry  *registry.Registry
    29  	Selector  *selector.Selector
    30  	Transport *transport.Transport
    31  	Config    *config.Config
    32  	Client    *client.Client
    33  	Server    *server.Server
    34  	Runtime   *runtime.Runtime
    35  	Store     *store.Store
    36  	Tracer    *trace.Tracer
    37  	Auth      *auth.Auth
    38  	Profile   *profile.Profile
    39  
    40  	Brokers    map[string]func(...broker.Option) broker.Broker
    41  	Configs    map[string]func(...config.Option) (config.Config, error)
    42  	Clients    map[string]func(...client.Option) client.Client
    43  	Registries map[string]func(...registry.Option) registry.Registry
    44  	Selectors  map[string]func(...selector.Option) selector.Selector
    45  	Servers    map[string]func(...server.Option) server.Server
    46  	Transports map[string]func(...transport.Option) transport.Transport
    47  	Runtimes   map[string]func(...runtime.Option) runtime.Runtime
    48  	Stores     map[string]func(...store.Option) store.Store
    49  	Tracers    map[string]func(...trace.Option) trace.Tracer
    50  	Auths      map[string]func(...auth.Option) auth.Auth
    51  	Profiles   map[string]func(...profile.Option) profile.Profile
    52  
    53  	// Other options for implementations of the interface
    54  	// can be stored in a context
    55  	Context context.Context
    56  }
    57  
    58  // Command line Name
    59  func Name(n string) Option {
    60  	return func(o *Options) {
    61  		o.Name = n
    62  	}
    63  }
    64  
    65  // Command line Description
    66  func Description(d string) Option {
    67  	return func(o *Options) {
    68  		o.Description = d
    69  	}
    70  }
    71  
    72  // Command line Version
    73  func Version(v string) Option {
    74  	return func(o *Options) {
    75  		o.Version = v
    76  	}
    77  }
    78  
    79  func Broker(b *broker.Broker) Option {
    80  	return func(o *Options) {
    81  		o.Broker = b
    82  	}
    83  }
    84  
    85  func Config(c *config.Config) Option {
    86  	return func(o *Options) {
    87  		o.Config = c
    88  	}
    89  }
    90  
    91  func Selector(s *selector.Selector) Option {
    92  	return func(o *Options) {
    93  		o.Selector = s
    94  	}
    95  }
    96  
    97  func Registry(r *registry.Registry) Option {
    98  	return func(o *Options) {
    99  		o.Registry = r
   100  	}
   101  }
   102  
   103  func Runtime(r *runtime.Runtime) Option {
   104  	return func(o *Options) {
   105  		o.Runtime = r
   106  	}
   107  }
   108  
   109  func Transport(t *transport.Transport) Option {
   110  	return func(o *Options) {
   111  		o.Transport = t
   112  	}
   113  }
   114  
   115  func Client(c *client.Client) Option {
   116  	return func(o *Options) {
   117  		o.Client = c
   118  	}
   119  }
   120  
   121  func Server(s *server.Server) Option {
   122  	return func(o *Options) {
   123  		o.Server = s
   124  	}
   125  }
   126  
   127  func Store(s *store.Store) Option {
   128  	return func(o *Options) {
   129  		o.Store = s
   130  	}
   131  }
   132  
   133  func Tracer(t *trace.Tracer) Option {
   134  	return func(o *Options) {
   135  		o.Tracer = t
   136  	}
   137  }
   138  
   139  func Auth(a *auth.Auth) Option {
   140  	return func(o *Options) {
   141  		o.Auth = a
   142  	}
   143  }
   144  
   145  func Profile(p *profile.Profile) Option {
   146  	return func(o *Options) {
   147  		o.Profile = p
   148  	}
   149  }
   150  
   151  // New broker func
   152  func NewBroker(name string, b func(...broker.Option) broker.Broker) Option {
   153  	return func(o *Options) {
   154  		o.Brokers[name] = b
   155  	}
   156  }
   157  
   158  // New client func
   159  func NewClient(name string, b func(...client.Option) client.Client) Option {
   160  	return func(o *Options) {
   161  		o.Clients[name] = b
   162  	}
   163  }
   164  
   165  // New registry func
   166  func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option {
   167  	return func(o *Options) {
   168  		o.Registries[name] = r
   169  	}
   170  }
   171  
   172  // New selector func
   173  func NewSelector(name string, s func(...selector.Option) selector.Selector) Option {
   174  	return func(o *Options) {
   175  		o.Selectors[name] = s
   176  	}
   177  }
   178  
   179  // New server func
   180  func NewServer(name string, s func(...server.Option) server.Server) Option {
   181  	return func(o *Options) {
   182  		o.Servers[name] = s
   183  	}
   184  }
   185  
   186  // New transport func
   187  func NewTransport(name string, t func(...transport.Option) transport.Transport) Option {
   188  	return func(o *Options) {
   189  		o.Transports[name] = t
   190  	}
   191  }
   192  
   193  // New runtime func
   194  func NewRuntime(name string, r func(...runtime.Option) runtime.Runtime) Option {
   195  	return func(o *Options) {
   196  		o.Runtimes[name] = r
   197  	}
   198  }
   199  
   200  // New tracer func
   201  func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option {
   202  	return func(o *Options) {
   203  		o.Tracers[name] = t
   204  	}
   205  }
   206  
   207  // New auth func
   208  func NewAuth(name string, t func(...auth.Option) auth.Auth) Option {
   209  	return func(o *Options) {
   210  		o.Auths[name] = t
   211  	}
   212  }