Help us shape the future of Go! Take the 2026 Go Developer Survey

cmd

package
v0.0.0-...-a11fdd8 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Overview

Package cmd is an interface for parsing the command line

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCmd = newCmd()

	DefaultFlags = []cli.Flag{
		&cli.StringFlag{
			Name:    "client",
			EnvVars: []string{"MICRO_CLIENT"},
			Usage:   "Client for go-micro; rpc",
		},
		&cli.StringFlag{
			Name:    "client_request_timeout",
			EnvVars: []string{"MICRO_CLIENT_REQUEST_TIMEOUT"},
			Usage:   "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s",
		},
		&cli.IntFlag{
			Name:    "client_retries",
			EnvVars: []string{"MICRO_CLIENT_RETRIES"},
			Value:   client.DefaultRetries,
			Usage:   "Sets the client retries. Default: 1",
		},
		&cli.IntFlag{
			Name:    "client_pool_size",
			EnvVars: []string{"MICRO_CLIENT_POOL_SIZE"},
			Usage:   "Sets the client connection pool size. Default: 1",
		},
		&cli.StringFlag{
			Name:    "client_pool_ttl",
			EnvVars: []string{"MICRO_CLIENT_POOL_TTL"},
			Usage:   "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m",
		},
		&cli.IntFlag{
			Name:    "register_ttl",
			EnvVars: []string{"MICRO_REGISTER_TTL"},
			Value:   60,
			Usage:   "Register TTL in seconds",
		},
		&cli.IntFlag{
			Name:    "register_interval",
			EnvVars: []string{"MICRO_REGISTER_INTERVAL"},
			Value:   30,
			Usage:   "Register interval in seconds",
		},
		&cli.StringFlag{
			Name:    "server",
			EnvVars: []string{"MICRO_SERVER"},
			Usage:   "Server for go-micro; rpc",
		},
		&cli.StringFlag{
			Name:    "server_name",
			EnvVars: []string{"MICRO_SERVER_NAME"},
			Usage:   "Name of the server. go.micro.srv.example",
		},
		&cli.StringFlag{
			Name:    "server_version",
			EnvVars: []string{"MICRO_SERVER_VERSION"},
			Usage:   "Version of the server. 1.1.0",
		},
		&cli.StringFlag{
			Name:    "server_id",
			EnvVars: []string{"MICRO_SERVER_ID"},
			Usage:   "Id of the server. Auto-generated if not specified",
		},
		&cli.StringFlag{
			Name:    "server_address",
			EnvVars: []string{"MICRO_SERVER_ADDRESS"},
			Usage:   "Bind address for the server. 127.0.0.1:8080",
		},
		&cli.StringFlag{
			Name:    "server_advertise",
			EnvVars: []string{"MICRO_SERVER_ADVERTISE"},
			Usage:   "Used instead of the server_address when registering with discovery. 127.0.0.1:8080",
		},
		&cli.StringSliceFlag{
			Name:    "server_metadata",
			EnvVars: []string{"MICRO_SERVER_METADATA"},
			Value:   &cli.StringSlice{},
			Usage:   "A list of key-value pairs defining metadata. version=1.0.0",
		},
		&cli.StringFlag{
			Name:    "broker",
			EnvVars: []string{"MICRO_BROKER"},
			Usage:   "Broker for pub/sub. http, nats, rabbitmq",
		},
		&cli.StringFlag{
			Name:    "broker_address",
			EnvVars: []string{"MICRO_BROKER_ADDRESS"},
			Usage:   "Comma-separated list of broker addresses",
		},
		&cli.StringFlag{
			Name:    "profile",
			Usage:   "Plugin profile to use. (local, nats, etc)",
			EnvVars: []string{"MICRO_PROFILE"},
		},
		&cli.StringFlag{
			Name:    "debug-profile",
			Usage:   "Debug Plugin profile to use.",
			EnvVars: []string{"MICRO_DEBUG_PROFILE"},
		},
		&cli.StringFlag{
			Name:    "registry",
			EnvVars: []string{"MICRO_REGISTRY"},
			Usage:   "Registry for discovery. etcd, mdns",
		},
		&cli.StringFlag{
			Name:    "registry_address",
			EnvVars: []string{"MICRO_REGISTRY_ADDRESS"},
			Usage:   "Comma-separated list of registry addresses",
		},
		&cli.StringFlag{
			Name:    "selector",
			EnvVars: []string{"MICRO_SELECTOR"},
			Usage:   "Selector used to pick nodes for querying",
		},
		&cli.StringFlag{
			Name:    "store",
			EnvVars: []string{"MICRO_STORE"},
			Usage:   "Store used for key-value storage",
		},
		&cli.StringFlag{
			Name:    "store_address",
			EnvVars: []string{"MICRO_STORE_ADDRESS"},
			Usage:   "Comma-separated list of store addresses",
		},
		&cli.StringFlag{
			Name:    "store_database",
			EnvVars: []string{"MICRO_STORE_DATABASE"},
			Usage:   "Database option for the underlying store",
		},
		&cli.StringFlag{
			Name:    "store_table",
			EnvVars: []string{"MICRO_STORE_TABLE"},
			Usage:   "Table option for the underlying store",
		},
		&cli.StringFlag{
			Name:    "transport",
			EnvVars: []string{"MICRO_TRANSPORT"},
			Usage:   "Transport mechanism used; http",
		},
		&cli.StringFlag{
			Name:    "transport_address",
			EnvVars: []string{"MICRO_TRANSPORT_ADDRESS"},
			Usage:   "Comma-separated list of transport addresses",
		},
		&cli.StringFlag{
			Name:    "tracer",
			EnvVars: []string{"MICRO_TRACER"},
			Usage:   "Tracer for distributed tracing, e.g. memory, jaeger",
		},
		&cli.StringFlag{
			Name:    "tracer_address",
			EnvVars: []string{"MICRO_TRACER_ADDRESS"},
			Usage:   "Comma-separated list of tracer addresses",
		},
		&cli.StringFlag{
			Name:    "auth",
			EnvVars: []string{"MICRO_AUTH"},
			Usage:   "Auth for role based access control, e.g. service",
		},
		&cli.StringFlag{
			Name:    "auth_id",
			EnvVars: []string{"MICRO_AUTH_ID"},
			Usage:   "Account ID used for client authentication",
		},
		&cli.StringFlag{
			Name:    "auth_secret",
			EnvVars: []string{"MICRO_AUTH_SECRET"},
			Usage:   "Account secret used for client authentication",
		},
		&cli.StringFlag{
			Name:    "auth_namespace",
			EnvVars: []string{"MICRO_AUTH_NAMESPACE"},
			Usage:   "Namespace for the services auth account",
			Value:   "go.micro",
		},
		&cli.StringFlag{
			Name:    "auth_public_key",
			EnvVars: []string{"MICRO_AUTH_PUBLIC_KEY"},
			Usage:   "Public key for JWT auth (base64 encoded PEM)",
		},
		&cli.StringFlag{
			Name:    "auth_private_key",
			EnvVars: []string{"MICRO_AUTH_PRIVATE_KEY"},
			Usage:   "Private key for JWT auth (base64 encoded PEM)",
		},
		&cli.StringFlag{
			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{
		"memory": broker.NewMemoryBroker,
		"http":   broker.NewHttpBroker,
	}

	DefaultClients = map[string]func(...client.Option) client.Client{}

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

	DefaultSelectors = map[string]func(...selector.Option) selector.Selector{}

	DefaultServers = map[string]func(...server.Option) server.Server{}

	DefaultTransports = map[string]func(...transport.Option) transport.Transport{}

	DefaultStores = map[string]func(...store.Option) store.Store{
		"memory": store.NewMemoryStore,
	}

	DefaultTracers = map[string]func(...trace.Option) trace.Tracer{}

	DefaultAuths = map[string]func(...auth.Option) auth.Auth{}

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

	DefaultConfigs = map[string]func(...config.Option) (config.Config, error){}

	DefaultCaches  = map[string]func(...cache.Option) cache.Cache{}
	DefaultStreams = map[string]func(...events.Option) (events.Stream, error){}
)

Functions

func App

func App() *cli.App

func Init

func Init(opts ...Option) error

func Register

func Register(cmds ...*cli.Command)

Register CLI commands

Types

type Cmd

type Cmd interface {
	// The cli app within this cmd
	App() *cli.App
	// Adds options, parses flags and initialize
	// 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 Auth

func Auth(a *auth.Auth) Option

func Broker

func Broker(b *broker.Broker) Option

func Cache

func Cache(c *cache.Cache) Option

func Client

func Client(c *client.Client) Option

func Config

func Config(c *config.Config) Option

func Description

func Description(d string) Option

Command line Description.

func Name

func Name(n string) Option

Command line Name.

func NewAuth

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

New auth func.

func NewBroker

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

New broker func.

func NewCache

func NewCache(name string, c func(...cache.Option) cache.Cache) Option

New cache func.

func NewClient

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

New client func.

func NewConfig

func NewConfig(name string, t func(...config.Option) (config.Config, error)) Option

New config func.

func NewProfile

func NewProfile(name string, t func(...profile.Option) profile.Profile) Option

New profile func.

func NewRegistry

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

New registry func.

func NewSelector

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

New selector func.

func NewServer

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

New server func.

func NewStream

func NewStream(name string, b func(...events.Option) events.Stream) Option

New stream func.

func NewTracer

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

New tracer func.

func NewTransport

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

New transport func.

func Profile

func Profile(p *profile.Profile) Option

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 Store

func Store(s *store.Store) Option

func Stream

func Stream(s *events.Stream) Option

func Tracer

func Tracer(t *trace.Tracer) Option

func Transport

func Transport(t *transport.Transport) Option

func Version

func Version(v string) Option

Command line Version.

type Options

type Options struct {

	// Other options for implementations of the interface
	// can be stored in a context
	Context      context.Context
	Auth         *auth.Auth
	Selector     *selector.Selector
	DebugProfile *profile.Profile

	Registry *registry.Registry

	Brokers       map[string]func(...broker.Option) broker.Broker
	Transport     *transport.Transport
	Cache         *cache.Cache
	Config        *config.Config
	Client        *client.Client
	Server        *server.Server
	Caches        map[string]func(...cache.Option) cache.Cache
	Tracer        *trace.Tracer
	DebugProfiles map[string]func(...profile.Option) profile.Profile

	// We need pointers to things so we can swap them out if needed.
	Broker     *broker.Broker
	Auths      map[string]func(...auth.Option) auth.Auth
	Store      *store.Store
	Stream     *events.Stream
	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
	Stores     map[string]func(...store.Option) store.Store
	Streams    map[string]func(...events.Option) events.Stream
	Tracers    map[string]func(...trace.Option) trace.Tracer
	Version    string

	// For the Command Line itself
	Name        string
	Description string
}

func DefaultOptions

func DefaultOptions() Options

Directories

Path Synopsis
api
Package api implements the 'micro api' command — a lightweight HTTP-to-RPC gateway that proxies JSON requests to go-micro services.
Package api implements the 'micro api' command — a lightweight HTTP-to-RPC gateway that proxies JSON requests to go-micro services.
cli
cli/build
Package build provides the micro build command for building service binaries
Package build provides the micro build command for building service binaries
cli/deploy
Package deploy provides the micro deploy command for deploying services
Package deploy provides the micro deploy command for deploying services
cli/gen
Package generate provides code generation commands for micro
Package generate provides code generation commands for micro
cli/init
Package initcmd provides the micro init command for server setup
Package initcmd provides the micro init command for server setup
cli/new
Package new generates micro service templates
Package new generates micro service templates
cli/remote
Package remote provides remote server operations for micro
Package remote provides remote server operations for micro
cli/util
Package cliutil contains methods used across all cli commands @todo: get rid of os.Exits and use errors instread
Package cliutil contains methods used across all cli commands @todo: get rid of os.Exits and use errors instread
resource
Package resource provides CLI commands that map directly onto go-micro's core interfaces — registry, broker, store, and config.
Package resource provides CLI commands that map directly onto go-micro's core interfaces — registry, broker, store, and config.
run
run/config
Package config handles micro.mu and micro.json configuration parsing
Package config handles micro.mu and micro.json configuration parsing
run/watcher
Package watcher provides file watching for hot reload
Package watcher provides file watching for hot reload
protoc-gen-micro is a plugin for the Google protocol buffer compiler to generate Go code.
protoc-gen-micro is a plugin for the Google protocol buffer compiler to generate Go code.
generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
protoc-gen-micro-gateway generates gateway HTTP rules (gateway/SPEC.md section 2.2) from google.api.http annotations: for each .proto file with annotated methods, a <file>.gateway.yaml next to it (relative to the output directory) holding an http_rules list to merge into the gateway rules document.
protoc-gen-micro-gateway generates gateway HTTP rules (gateway/SPEC.md section 2.2) from google.api.http annotations: for each .proto file with annotated methods, a <file>.gateway.yaml next to it (relative to the output directory) holding an http_rules list to merge into the gateway rules document.

Jump to

Keyboard shortcuts

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