Documentation ¶
Index ¶
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat32(key string) float32
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt16(key string) int16
- func GetInt32(key string) int32
- func GetInt64(key string) int64
- func GetInt8(key string) int8
- func GetString(key string) string
- func GetStringSlice(key string) []string
- func GetUint(key string) uint
- func GetUint16(key string) uint16
- func GetUint32(key string) uint32
- func GetUint64(key string) uint64
- func GetUint8(key string) uint8
- func IsSet(key string) bool
- func Set(key string, value interface{})
- type CustomOption
- type NirvanaCommand
- type NirvanaCommandHook
- type NirvanaCommandHookFunc
- func (h *NirvanaCommandHookFunc) PostConfigure(config *nirvana.Config) error
- func (h *NirvanaCommandHookFunc) PostServe(config *nirvana.Config, server nirvana.Server, err error) error
- func (h *NirvanaCommandHookFunc) PreConfigure(config *nirvana.Config) error
- func (h *NirvanaCommandHookFunc) PreServe(config *nirvana.Config, server nirvana.Server) error
- type Option
- type Plugin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get(key string) interface{}
Get can retrieve any value given the key to use. Get is case-insensitive for a key. Get has the behavior of returning the value associated with the first place from where it is set. Viper will check in the following order: override, flag, env, config file, key/value store, default
Get returns an interface. For a specific value use one of the Get____ methods.
func GetDuration ¶
GetDuration returns the value associated with the key as a time.Duration.
func GetFloat32 ¶
GetFloat32 returns the value associated with the key as a float32.
func GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func GetStringSlice ¶
GetStringSlice returns the value associated with the key as a []string.
Types ¶
type CustomOption ¶
type CustomOption interface{}
CustomOption must be a pointer to struct.
Here is an example:
type Option struct { FirstName string `desc:"Desc for First Name"` Age uint16 `desc:"Desc for Age"` }
The struct has two fields (with prefix example):
Field Flag ENV Key (In config file) FirstName --example-first-name EXAMPLE_FIRST_NAME example.firstName Age --example-age EXAMPLE_AGE example.age
When you execute command with `--help`, you can see the help doc of flags and descriptions (From field tag `desc`).
The priority is:
Flag > ENV > Key > The value you set in option
type NirvanaCommand ¶
type NirvanaCommand interface { // EnablePlugin enables plugins. EnablePlugin(plugins ...Plugin) NirvanaCommand // AddOption will fill up options from flags/ENV/config after executing. // A non-empty prefix is recommended. It's used to divide option namespaces. AddOption(prefix string, options ...CustomOption) NirvanaCommand // Add adds a field by key. // If you don't have any struct to describe an option, you can use the method to // add a single field into nirvana command. // `pointer` must be a pointer to golang basic data type (e.g. *int, *string). // `key` must a config key. It's like 'nirvana.ip' and 'myconfig.name.firstName'. // The key will be converted to flag and env (e.g. --nirvana-ip and NIRVANA_IP). // If you want a short flag for the field, you can only set a one-char string. // `desc` describes the field. Add(pointer interface{}, key string, shortFlag string, desc string) NirvanaCommand // Execute runs nirvana server. Execute(descriptors ...definition.Descriptor) error // ExecuteWithConfig runs nirvana server from a custom config. ExecuteWithConfig(cfg *nirvana.Config) error // Command returns a command for command. Command(cfg *nirvana.Config) *cobra.Command // SetHook sets nirvana command hook. SetHook(hook NirvanaCommandHook) // Hook returns nirvana command hook. Hook() NirvanaCommandHook }
NirvanaCommand is a nirvana command.
func NewDefaultNirvanaCommand ¶
func NewDefaultNirvanaCommand() NirvanaCommand
NewDefaultNirvanaCommand creates a nirvana command with default option.
func NewNamedNirvanaCommand ¶
func NewNamedNirvanaCommand(name string, option *Option) NirvanaCommand
NewNamedNirvanaCommand creates a nirvana command with an unique name. Empty name means `server`. Nil option means default option.
func NewNirvanaCommand ¶
func NewNirvanaCommand(option *Option) NirvanaCommand
NewNirvanaCommand creates a nirvana command. Nil option means default option.
type NirvanaCommandHook ¶
type NirvanaCommandHook interface { // PreConfigure runs before installing plugins. PreConfigure(config *nirvana.Config) error // PostConfigure runs after installing plugins and before creating nirvana server. PostConfigure(config *nirvana.Config) error // PreServe runs before nirvana server serving. PreServe(config *nirvana.Config, server nirvana.Server) error // PostServe runs after nirvana server shutting down or any error occurring. PostServe(config *nirvana.Config, server nirvana.Server, err error) error }
NirvanaCommandHook provides several hook points for NirvanaCommand.
type NirvanaCommandHookFunc ¶
type NirvanaCommandHookFunc struct { PreConfigureFunc func(config *nirvana.Config) error PostConfigureFunc func(config *nirvana.Config) error PreServeFunc func(config *nirvana.Config, server nirvana.Server) error PostServeFunc func(config *nirvana.Config, server nirvana.Server, err error) error }
NirvanaCommandHookFunc is a helper to generate NirvanaCommandHook. Hook points are optional.
func (*NirvanaCommandHookFunc) PostConfigure ¶
func (h *NirvanaCommandHookFunc) PostConfigure(config *nirvana.Config) error
PostConfigure runs after installing plugins and before creating nirvana server.
func (*NirvanaCommandHookFunc) PostServe ¶
func (h *NirvanaCommandHookFunc) PostServe(config *nirvana.Config, server nirvana.Server, err error) error
PostServe runs after nirvana server shutting down or any error occurring.
func (*NirvanaCommandHookFunc) PreConfigure ¶
func (h *NirvanaCommandHookFunc) PreConfigure(config *nirvana.Config) error
PreConfigure runs before installing plugins.
type Option ¶
type Option struct { // IP is the IP to listen. IP string `desc:"Nirvana server listening IP"` // Port is the port to listen. Port uint16 `desc:"Nirvana server listening Port"` // Key is private key for HTTPS. Key string `desc:"TLS private key (PEM format) for HTTPS"` // Cert is certificate for HTTPS. Cert string `desc:"TLS certificate (PEM format) for HTTPS"` }
Option contains basic configurations of nirvana.