cmd

package
v1.4.8-alpha-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 30 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCmd = newCmd()

	DefaultFlags = []cli.Flag{
		&cli.StringFlag{
			Name:    "client",
			EnvVars: []string{"VINE_CLIENT"},
			Usage:   "Client for vine; rpc",
		},
		&cli.StringFlag{
			Name:    "client-request-timeout",
			EnvVars: []string{"VINE_CLIENT_REQUEST_TIMEOUT"},
			Usage:   "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s",
		},
		&cli.IntFlag{
			Name:    "client-retries",
			EnvVars: []string{"VINE_CLIENT_RETIES"},
			Value:   client.DefaultRetries,
			Usage:   "Sets the client retries. Default: 1",
		},
		&cli.IntFlag{
			Name:    "client-pool-size",
			EnvVars: []string{"VINE_CLIENT_POOL_SIZE"},
			Usage:   "Sets the client connection pool size. Default: 1",
		},
		&cli.StringFlag{
			Name:    "client-pool-ttl",
			EnvVars: []string{"VINE_CLIENT_POOL_TTL"},
			Usage:   "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m",
		},
		&cli.IntFlag{
			Name:    "register-ttl",
			EnvVars: []string{"VINE_REGISTER_TTL"},
			Value:   60,
			Usage:   "Register TTL in seconds",
		},
		&cli.IntFlag{
			Name:    "register-interval",
			EnvVars: []string{"VINE_REGISTER_INTERVAL"},
			Value:   30,
			Usage:   "Register interval in seconds",
		},
		&cli.StringFlag{
			Name:    "server",
			EnvVars: []string{"VINE_SERVER"},
			Usage:   "Server for vine; rpc",
		},
		&cli.StringFlag{
			Name:    "server-name",
			EnvVars: []string{"VINE_SERVER_NAME"},
			Usage:   "Name of the server. go.vine.svc.example",
		},
		&cli.StringFlag{
			Name:    "server-version",
			EnvVars: []string{"VINE_SERVER_VERSION"},
			Usage:   "Version of the server. 1.1.0",
		},
		&cli.StringFlag{
			Name:    "server-id",
			EnvVars: []string{"VINE_SERVER_ID"},
			Usage:   "Id of the server. Auto-generated if not specified",
		},
		&cli.StringFlag{
			Name:    "server-address",
			EnvVars: []string{"VINE_SERVER_ADDRESS"},
			Usage:   "Bind address for the server. 127.0.0.1:8080",
		},
		&cli.StringFlag{
			Name:    "server-advertise",
			EnvVars: []string{"VINE_SERVER_ADVERTISE"},
			Usage:   "Use instead of the server-address when registering with discovery. 127.0.0.1:8080",
		},
		&cli.StringSliceFlag{
			Name:    "server-metadata",
			EnvVars: []string{"VINE_SERVER_METADATA"},
			Value:   &cli.StringSlice{},
			Usage:   "A list of key-value pairs defining metadata. version=1.0.0",
		},
		&cli.StringFlag{
			Name:    "broker",
			EnvVars: []string{"VINE_BROKER"},
			Usage:   "Broker for pub/sub. http, nats",
		},
		&cli.StringFlag{
			Name:    "broker-address",
			EnvVars: []string{"VINE_BROKER_ADDRESS"},
			Usage:   "Comma-separated list of broker addresses",
		},
		&cli.StringFlag{
			Name:    "registry",
			EnvVars: []string{"VINE_REGISTRY"},
			Usage:   "Registry for discovery. memory, mdns",
		},
		&cli.StringFlag{
			Name:    "registry-address",
			EnvVars: []string{"VINE_REGISTRY_ADDRESS"},
			Usage:   "Comma-separated list of registry addresses",
		},
		&cli.StringFlag{
			Name:    "selector",
			EnvVars: []string{"VINE_SELECTOR"},
			Usage:   "Selector used to pick nodes for querying",
		},
		&cli.StringFlag{
			Name:    "dao-dialect",
			EnvVars: []string{"VINE_DAO_DIALECT"},
			Usage:   "Database option for the underlying dao",
		},
		&cli.StringFlag{
			Name:    "dao-dsn",
			EnvVars: []string{"VINE_DSN"},
			Usage:   "DSN database driver name for underlying dao",
		},
		&cli.StringFlag{
			Name:    "config",
			EnvVars: []string{"VINE_CONFIG"},
			Usage:   "The source of the config to be used to get configuration",
		},
		&cli.StringFlag{
			Name:    "cache",
			EnvVars: []string{"VINE_CACHE"},
			Usage:   "Cache used for key-value storage",
		},
		&cli.StringFlag{
			Name:    "cache-address",
			EnvVars: []string{"VINE_CACHE_ADDRESS"},
			Usage:   "Comma-separated list of cache addresses",
		},
		&cli.StringFlag{
			Name:    "tracer",
			EnvVars: []string{"VINE_TRACER"},
			Usage:   "Tracer for distributed tracing, e.g. memory, jaeger",
		},
		&cli.StringFlag{
			Name:    "tracer-address",
			EnvVars: []string{"VINE_TRACER_ADDRESS"},
			Usage:   "Comma-separated list of tracer addresses",
		},
	}

	DefaultBrokers = map[string]func(...broker.Option) broker.Broker{
		"memory": memory.NewBroker,
		"http":   brokerHttp.NewBroker,
	}

	DefaultClients = map[string]func(...client.Option) client.Client{
		"grpc": cGrpc.NewClient,
	}

	DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
		"mdns":   mdns.NewRegistry,
		"memory": regMemory.NewRegistry,
	}

	DefaultSelectors = map[string]func(...selector.Option) selector.Selector{
		"dns":    dns.NewSelector,
		"static": static.NewSelector,
	}

	DefaultServers = map[string]func(...server.Option) server.Server{
		"grpc": sgrpc.NewServer,
	}

	DefaultDialects = map[string]func(...dao.Option) dao.Dialect{
		"nop": daoNop.NewDialect,
	}

	DefaultCaches = map[string]func(...cache.Option) cache.Cache{
		"memory": memCache.NewCache,
		"noop":   nopCache.NewCache,
	}

	DefaultTracers = map[string]func(...trace.Option) trace.Tracer{
		"memory": memTracer.NewTracer,
	}

	DefaultConfigs = map[string]func(...config.Option) config.Config{
		"memory": configMemory.NewConfig,
	}
)

Functions

func App

func App() *cli.App

func Init

func Init(opts ...Option) error

Types

type Cmd

type Cmd interface {
	// App The cli app within this cmd
	App() *cli.App
	// Init Adds options, parses flags and initialise
	// exits on error
	Init(opts ...Option) error
	// Options set within this command
	Options() Options
}

func NewCmd

func NewCmd(opts ...Option) Cmd

type Option

type Option func(o *Options)

func Broker

func Broker(b *broker.Broker) Option

func Cache

func Cache(c *cache.Cache) Option

func CliApp

func CliApp(app *cli.App) Option

func Client

func Client(c *client.Client) Option

func Config

func Config(c *config.Config) Option

func Description

func Description(d string) Option

Description command line Description

func Dialect

func Dialect(d *dao.Dialect) Option

func Name

func Name(n string) Option

Name command line Name

func NewBroker

func NewBroker(name string, b func(...broker.Option) broker.Broker) Option

NewBroker new broker func

func NewClient

func NewClient(name string, b func(...client.Option) client.Client) Option

NewClient new client func

func NewDialect

func NewDialect(name string, t func(...dao.Option) dao.Dialect) Option

NewDialect new dao func

func NewRegistry

func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option

NewRegistry new registry func

func NewSelector

func NewSelector(name string, s func(...selector.Option) selector.Selector) Option

NewSelector new selector func

func NewServer

func NewServer(name string, s func(...server.Option) server.Server) Option

NewServer new server func

func NewTracer

func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option

NewTracer new tracer func

func Registry

func Registry(r *registry.Registry) Option

func Selector

func Selector(s *selector.Selector) Option

func Server

func Server(s *server.Server) Option

func Tracer

func Tracer(t *trace.Tracer) Option

func Version

func Version(v string) Option

Version command line Version

type Options

type Options struct {
	// For the Command Line itself
	Name        string
	Description string
	Version     string

	// We need pointers to things, so we can swap them out if needed.
	Broker   *broker.Broker
	Registry *registry.Registry
	Selector *selector.Selector
	Config   *config.Config
	Client   *client.Client
	Server   *server.Server
	Dialect  *dao.Dialect
	Cache    *cache.Cache
	Tracer   *trace.Tracer

	Brokers    map[string]func(...broker.Option) broker.Broker
	Configs    map[string]func(...config.Option) config.Config
	Clients    map[string]func(...client.Option) client.Client
	Registries map[string]func(...registry.Option) registry.Registry
	Selectors  map[string]func(...selector.Option) selector.Selector
	Servers    map[string]func(...server.Option) server.Server
	Dialects   map[string]func(...dao.Option) dao.Dialect
	Caches     map[string]func(...cache.Option) cache.Cache
	Tracers    map[string]func(...trace.Option) trace.Tracer

	// Other options for implementations of the interfaces
	// can be stored in a context
	Context context.Context
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions() Options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL