2016-01-01 01:16:21 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-03 11:53:52 +00:00
|
|
|
"context"
|
|
|
|
|
2016-01-01 01:16:21 +00:00
|
|
|
"github.com/micro/go-micro/broker"
|
2016-01-02 00:38:57 +00:00
|
|
|
"github.com/micro/go-micro/client"
|
2019-06-21 15:13:54 +01:00
|
|
|
"github.com/micro/go-micro/client/selector"
|
2019-06-21 17:20:41 +01:00
|
|
|
"github.com/micro/go-micro/registry"
|
2019-11-02 13:25:10 +00:00
|
|
|
"github.com/micro/go-micro/runtime"
|
2016-01-02 00:38:57 +00:00
|
|
|
"github.com/micro/go-micro/server"
|
2019-07-10 07:47:17 +01:00
|
|
|
"github.com/micro/go-micro/transport"
|
2016-01-01 01:16:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2016-01-02 00:38:57 +00:00
|
|
|
// For the Command Line itself
|
2016-01-01 01:16:21 +00:00
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Version string
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// We need pointers to things so we can swap them out if needed.
|
|
|
|
Broker *broker.Broker
|
|
|
|
Registry *registry.Registry
|
|
|
|
Selector *selector.Selector
|
|
|
|
Transport *transport.Transport
|
|
|
|
Client *client.Client
|
|
|
|
Server *server.Server
|
2019-11-02 13:25:10 +00:00
|
|
|
Runtime *runtime.Runtime
|
2016-01-02 00:38:57 +00:00
|
|
|
|
2016-03-15 22:12:28 +00:00
|
|
|
Brokers map[string]func(...broker.Option) broker.Broker
|
2016-11-18 17:29:26 +00:00
|
|
|
Clients map[string]func(...client.Option) client.Client
|
2016-03-15 22:20:21 +00:00
|
|
|
Registries map[string]func(...registry.Option) registry.Registry
|
2016-01-01 01:16:21 +00:00
|
|
|
Selectors map[string]func(...selector.Option) selector.Selector
|
2016-11-18 17:29:26 +00:00
|
|
|
Servers map[string]func(...server.Option) server.Server
|
2016-03-15 22:25:32 +00:00
|
|
|
Transports map[string]func(...transport.Option) transport.Transport
|
2019-11-02 13:25:10 +00:00
|
|
|
Runtimes map[string]func(...runtime.Option) runtime.Runtime
|
2016-01-06 16:25:12 +00:00
|
|
|
|
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2016-01-01 01:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// Command line Name
|
2016-01-01 01:16:21 +00:00
|
|
|
func Name(n string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Name = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// Command line Description
|
2016-01-01 01:16:21 +00:00
|
|
|
func Description(d string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Description = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// Command line Version
|
2016-01-01 01:16:21 +00:00
|
|
|
func Version(v string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Version = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
func Broker(b *broker.Broker) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Broker = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Selector(s *selector.Selector) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Selector = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Registry(r *registry.Registry) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Registry = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Transport(t *transport.Transport) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Transport = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Client(c *client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Client = c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Server(s *server.Server) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Server = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// New broker func
|
2016-03-15 22:12:28 +00:00
|
|
|
func NewBroker(name string, b func(...broker.Option) broker.Broker) Option {
|
2016-01-01 01:16:21 +00:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Brokers[name] = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 17:29:26 +00:00
|
|
|
// New client func
|
|
|
|
func NewClient(name string, b func(...client.Option) client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Clients[name] = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// New registry func
|
2016-03-15 22:20:21 +00:00
|
|
|
func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option {
|
2016-01-01 01:16:21 +00:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Registries[name] = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// New selector func
|
|
|
|
func NewSelector(name string, s func(...selector.Option) selector.Selector) Option {
|
2016-01-01 01:16:21 +00:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Selectors[name] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 17:29:26 +00:00
|
|
|
// New server func
|
|
|
|
func NewServer(name string, s func(...server.Option) server.Server) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Servers[name] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 00:38:57 +00:00
|
|
|
// New transport func
|
2016-03-15 22:25:32 +00:00
|
|
|
func NewTransport(name string, t func(...transport.Option) transport.Transport) Option {
|
2016-01-01 01:16:21 +00:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Transports[name] = t
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 13:25:10 +00:00
|
|
|
|
|
|
|
// New runtime func
|
|
|
|
func NewRuntime(name string, r func(...runtime.Option) runtime.Runtime) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Runtimes[name] = r
|
|
|
|
}
|
|
|
|
}
|