go-micro: github.com/micro/go-micro/config/cmd Index | Files

package cmd

import "github.com/micro/go-micro/config/cmd"

Package cmd is an interface for parsing the command line


Package Files

cmd.go options.go


var (
    DefaultCmd = newCmd()

    DefaultFlags = []cli.Flag{
            Name:    "client",
            EnvVars: []string{"MICRO_CLIENT"},
            Usage:   "Client for go-micro; rpc",
            Name:    "client_request_timeout",
            EnvVars: []string{"MICRO_CLIENT_REQUEST_TIMEOUT"},
            Usage:   "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s",
            Name:    "client_retries",
            EnvVars: []string{"MICRO_CLIENT_RETRIES"},
            Value:   client.DefaultRetries,
            Usage:   "Sets the client retries. Default: 1",
            Name:    "client_pool_size",
            EnvVars: []string{"MICRO_CLIENT_POOL_SIZE"},
            Usage:   "Sets the client connection pool size. Default: 1",
            Name:    "client_pool_ttl",
            EnvVars: []string{"MICRO_CLIENT_POOL_TTL"},
            Usage:   "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m",
            Name:    "register_ttl",
            EnvVars: []string{"MICRO_REGISTER_TTL"},
            Value:   60,
            Usage:   "Register TTL in seconds",
            Name:    "register_interval",
            EnvVars: []string{"MICRO_REGISTER_INTERVAL"},
            Value:   30,
            Usage:   "Register interval in seconds",
            Name:    "server",
            EnvVars: []string{"MICRO_SERVER"},
            Usage:   "Server for go-micro; rpc",
            Name:    "server_name",
            EnvVars: []string{"MICRO_SERVER_NAME"},
            Usage:   "Name of the server. go.micro.srv.example",
            Name:    "server_version",
            EnvVars: []string{"MICRO_SERVER_VERSION"},
            Usage:   "Version of the server. 1.1.0",
            Name:    "server_id",
            EnvVars: []string{"MICRO_SERVER_ID"},
            Usage:   "Id of the server. Auto-generated if not specified",
            Name:    "server_address",
            EnvVars: []string{"MICRO_SERVER_ADDRESS"},
            Usage:   "Bind address for the server.",
            Name:    "server_advertise",
            EnvVars: []string{"MICRO_SERVER_ADVERTISE"},
            Usage:   "Used instead of the server_address when registering with discovery.",
            Name:    "server_metadata",
            EnvVars: []string{"MICRO_SERVER_METADATA"},
            Value:   &cli.StringSlice{},
            Usage:   "A list of key-value pairs defining metadata. version=1.0.0",
            Name:    "broker",
            EnvVars: []string{"MICRO_BROKER"},
            Usage:   "Broker for pub/sub. http, nats, rabbitmq",
            Name:    "broker_address",
            EnvVars: []string{"MICRO_BROKER_ADDRESS"},
            Usage:   "Comma-separated list of broker addresses",
            Name:    "profile",
            Usage:   "Debug profiler for cpu and memory stats",
            EnvVars: []string{"MICRO_DEBUG_PROFILE"},
            Name:    "registry",
            EnvVars: []string{"MICRO_REGISTRY"},
            Usage:   "Registry for discovery. etcd, mdns",
            Name:    "registry_address",
            EnvVars: []string{"MICRO_REGISTRY_ADDRESS"},
            Usage:   "Comma-separated list of registry addresses",
            Name:    "runtime",
            Usage:   "Runtime for building and running services e.g local, kubernetes",
            EnvVars: []string{"MICRO_RUNTIME"},
            Value:   "local",
            Name:    "runtime_source",
            Usage:   "Runtime source for building and running services e.g github.com/micro/service",
            EnvVars: []string{"MICRO_RUNTIME_SOURCE"},
            Value:   "github.com/micro/services",
            Name:    "selector",
            EnvVars: []string{"MICRO_SELECTOR"},
            Usage:   "Selector used to pick nodes for querying",
            Name:    "store",
            EnvVars: []string{"MICRO_STORE"},
            Usage:   "Store used for key-value storage",
            Name:    "store_address",
            EnvVars: []string{"MICRO_STORE_ADDRESS"},
            Usage:   "Comma-separated list of store addresses",
            Name:    "store_namespace",
            EnvVars: []string{"MICRO_STORE_NAMESPACE"},
            Usage:   "Namespace for store data",
            Name:    "transport",
            EnvVars: []string{"MICRO_TRANSPORT"},
            Usage:   "Transport mechanism used; http",
            Name:    "transport_address",
            EnvVars: []string{"MICRO_TRANSPORT_ADDRESS"},
            Usage:   "Comma-separated list of transport addresses",
            Name:    "tracer",
            EnvVars: []string{"MICRO_TRACER"},
            Usage:   "Tracer for distributed tracing, e.g. memory, jaeger",
            Name:    "tracer_address",
            EnvVars: []string{"MICRO_TRACER_ADDRESS"},
            Usage:   "Comma-separated list of tracer addresses",
            Name:    "auth",
            EnvVars: []string{"MICRO_AUTH"},
            Usage:   "Auth for role based access control, e.g. service",
            Name:    "auth_token",
            EnvVars: []string{"MICRO_AUTH_TOKEN"},
            Usage:   "Auth token used for client authentication",
            Name:    "auth_public_key",
            EnvVars: []string{"MICRO_AUTH_PUBLIC_KEY"},
            Usage:   "Public key for JWT auth (base64 encoded PEM)",
            Name:    "auth_private_key",
            EnvVars: []string{"MICRO_AUTH_PRIVATE_KEY"},
            Usage:   "Private key for JWT auth (base64 encoded PEM)",
            Name:    "auth_provider",
            EnvVars: []string{"MICRO_AUTH_PROVIDER"},
            Usage:   "Auth provider used to login user",
            Name:    "auth_provider_client_id",
            EnvVars: []string{"MICRO_AUTH_PROVIDER_CLIENT_ID"},
            Usage:   "The client id to be used for oauth",
            Name:    "auth_provider_client_secret",
            EnvVars: []string{"MICRO_AUTH_PROVIDER_CLIENT_SECRET"},
            Usage:   "The client secret to be used for oauth",
            Name:    "auth_provider_endpoint",
            EnvVars: []string{"MICRO_AUTH_PROVIDER_ENDPOINT"},
            Usage:   "The enpoint to be used for oauth",
            Name:    "auth_provider_redirect",
            EnvVars: []string{"MICRO_AUTH_PROVIDER_REDIRECT"},
            Usage:   "The redirect to be used for oauth",
            Name:    "auth_provider_scope",
            EnvVars: []string{"MICRO_AUTH_PROVIDER_SCOPE"},
            Usage:   "The scope to be used for oauth",
            Name:    "config",
            EnvVars: []string{"MICRO_CONFIG"},
            Usage:   "The source of the config to be used to get configuration",

    DefaultBrokers = map[string]func(...broker.Option) broker.Broker{
        "service": brokerSrv.NewBroker,
        "memory":  memory.NewBroker,
        "nats":    nats.NewBroker,

    DefaultClients = map[string]func(...client.Option) client.Client{
        "mucp": cmucp.NewClient,
        "grpc": cgrpc.NewClient,

    DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
        "service":    regSrv.NewRegistry,
        "etcd":       etcd.NewRegistry,
        "mdns":       mdns.NewRegistry,
        "memory":     rmem.NewRegistry,
        "kubernetes": kreg.NewRegistry,

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

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

    DefaultTransports = map[string]func(...transport.Option) transport.Transport{
        "memory": tmem.NewTransport,
        "http":   thttp.NewTransport,

    DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{
        "local":      lRuntime.NewRuntime,
        "service":    srvRuntime.NewRuntime,
        "kubernetes": kRuntime.NewRuntime,

    DefaultStores = map[string]func(...store.Option) store.Store{
        "memory":  memStore.NewStore,
        "service": svcStore.NewStore,

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

    DefaultAuths = map[string]func(...auth.Option) auth.Auth{
        "service": svcAuth.NewAuth,

    DefaultAuthProviders = map[string]func(...provider.Option) provider.Provider{
        "oauth": oauth.NewProvider,
        "basic": basic.NewProvider,

    DefaultProfiles = map[string]func(...profile.Option) profile.Profile{
        "http":  http.NewProfile,
        "pprof": pprof.NewProfile,

    DefaultConfigs = map[string]func(...config.Option) (config.Config, error){
        "service": config.NewConfig,

func App Uses

func App() *cli.App

func Init Uses

func Init(opts ...Option) error

type Cmd Uses

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

func NewCmd Uses

func NewCmd(opts ...Option) Cmd

type Option Uses

type Option func(o *Options)

func Auth Uses

func Auth(a *auth.Auth) Option

func Broker Uses

func Broker(b *broker.Broker) Option

func Client Uses

func Client(c *client.Client) Option

func Config Uses

func Config(c *config.Config) Option

func Description Uses

func Description(d string) Option

Command line Description

func Name Uses

func Name(n string) Option

Command line Name

func NewAuth Uses

func NewAuth(name string, t func(...auth.Option) auth.Auth) Option

New auth func

func NewBroker Uses

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

New broker func

func NewClient Uses

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

New client func

func NewRegistry Uses

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

New registry func

func NewRuntime Uses

func NewRuntime(name string, r func(...runtime.Option) runtime.Runtime) Option

New runtime func

func NewSelector Uses

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

New selector func

func NewServer Uses

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

New server func

func NewTracer Uses

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

New tracer func

func NewTransport Uses

func NewTransport(name string, t func(...transport.Option) transport.Transport) Option

New transport func

func Profile Uses

func Profile(p *profile.Profile) Option

func Registry Uses

func Registry(r *registry.Registry) Option

func Selector Uses

func Selector(s *selector.Selector) Option

func Server Uses

func Server(s *server.Server) Option

func Tracer Uses

func Tracer(t *trace.Tracer) Option

func Transport Uses

func Transport(t *transport.Transport) Option

func Version Uses

func Version(v string) Option

Command line Version

type Options Uses

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
    Transport *transport.Transport
    Config    *config.Config
    Client    *client.Client
    Server    *server.Server
    Runtime   *runtime.Runtime
    Store     *store.Store
    Tracer    *trace.Tracer
    Auth      *auth.Auth
    Profile   *profile.Profile

    Brokers    map[string]func(...broker.Option) broker.Broker
    Configs    map[string]func(...config.Option) (config.Config, error)
    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
    Transports map[string]func(...transport.Option) transport.Transport
    Runtimes   map[string]func(...runtime.Option) runtime.Runtime
    Stores     map[string]func(...store.Option) store.Store
    Tracers    map[string]func(...trace.Option) trace.Tracer
    Auths      map[string]func(...auth.Option) auth.Auth
    Profiles   map[string]func(...profile.Option) profile.Profile

    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

func DefaultOptions Uses

func DefaultOptions() Options

Package cmd imports 49 packages (graph) and is imported by 58 packages. Updated 2020-03-28. Refresh now. Tools for package owners.