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

package cmd

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

Package cmd is an interface for parsing the command line

Index

Package Files

cmd.go options.go

Variables

var (
    DefaultCmd = newCmd()

    DefaultFlags = []cli.Flag{
        cli.StringFlag{
            Name:   "client",
            EnvVar: "MICRO_CLIENT",
            Usage:  "Client for go-micro; rpc",
        },
        cli.StringFlag{
            Name:   "client_request_timeout",
            EnvVar: "MICRO_CLIENT_REQUEST_TIMEOUT",
            Usage:  "Sets the client request timeout. e.g 500ms, 5s, 1m. Default: 5s",
        },
        cli.IntFlag{
            Name:   "client_retries",
            EnvVar: "MICRO_CLIENT_RETRIES",
            Usage:  "Sets the client retries. Default: 1",
        },
        cli.IntFlag{
            Name:   "client_pool_size",
            EnvVar: "MICRO_CLIENT_POOL_SIZE",
            Usage:  "Sets the client connection pool size. Default: 1",
        },
        cli.StringFlag{
            Name:   "client_pool_ttl",
            EnvVar: "MICRO_CLIENT_POOL_TTL",
            Usage:  "Sets the client connection pool ttl. e.g 500ms, 5s, 1m. Default: 1m",
        },
        cli.IntFlag{
            Name:   "register_ttl",
            EnvVar: "MICRO_REGISTER_TTL",
            Usage:  "Register TTL in seconds",
        },
        cli.IntFlag{
            Name:   "register_interval",
            EnvVar: "MICRO_REGISTER_INTERVAL",
            Usage:  "Register interval in seconds",
        },
        cli.StringFlag{
            Name:   "server",
            EnvVar: "MICRO_SERVER",
            Usage:  "Server for go-micro; rpc",
        },
        cli.StringFlag{
            Name:   "server_name",
            EnvVar: "MICRO_SERVER_NAME",
            Usage:  "Name of the server. go.micro.srv.example",
        },
        cli.StringFlag{
            Name:   "server_version",
            EnvVar: "MICRO_SERVER_VERSION",
            Usage:  "Version of the server. 1.1.0",
        },
        cli.StringFlag{
            Name:   "server_id",
            EnvVar: "MICRO_SERVER_ID",
            Usage:  "Id of the server. Auto-generated if not specified",
        },
        cli.StringFlag{
            Name:   "server_address",
            EnvVar: "MICRO_SERVER_ADDRESS",
            Usage:  "Bind address for the server. 127.0.0.1:8080",
        },
        cli.StringFlag{
            Name:   "server_advertise",
            EnvVar: "MICRO_SERVER_ADVERTISE",
            Usage:  "Used instead of the server_address when registering with discovery. 127.0.0.1:8080",
        },
        cli.StringSliceFlag{
            Name:   "server_metadata",
            EnvVar: "MICRO_SERVER_METADATA",
            Value:  &cli.StringSlice{},
            Usage:  "A list of key-value pairs defining metadata. version=1.0.0",
        },
        cli.StringFlag{
            Name:   "broker",
            EnvVar: "MICRO_BROKER",
            Usage:  "Broker for pub/sub. http, nats, rabbitmq",
        },
        cli.StringFlag{
            Name:   "broker_address",
            EnvVar: "MICRO_BROKER_ADDRESS",
            Usage:  "Comma-separated list of broker addresses",
        },
        cli.StringFlag{
            Name:   "registry",
            EnvVar: "MICRO_REGISTRY",
            Usage:  "Registry for discovery. consul, mdns",
        },
        cli.StringFlag{
            Name:   "registry_address",
            EnvVar: "MICRO_REGISTRY_ADDRESS",
            Usage:  "Comma-separated list of registry addresses",
        },
        cli.StringFlag{
            Name:   "selector",
            EnvVar: "MICRO_SELECTOR",
            Usage:  "Selector used to pick nodes for querying",
            Value:  "cache",
        },
        cli.StringFlag{
            Name:   "transport",
            EnvVar: "MICRO_TRANSPORT",
            Usage:  "Transport mechanism used; http",
        },
        cli.StringFlag{
            Name:   "transport_address",
            EnvVar: "MICRO_TRANSPORT_ADDRESS",
            Usage:  "Comma-separated list of transport addresses",
        },
    }

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

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

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

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

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

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

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 Broker Uses

func Broker(b *broker.Broker) Option

func Client Uses

func Client(c *client.Client) Option

func Description Uses

func Description(d string) Option

Command line Description

func Name Uses

func Name(n string) Option

Command line Name

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 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 NewTransport Uses

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

New transport func

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 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
    Client    *client.Client
    Server    *server.Server

    Brokers    map[string]func(...broker.Option) broker.Broker
    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

    // 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 21 packages (graph) and is imported by 281 packages. Updated 2018-12-06. Refresh now. Tools for package owners.