Documentation
¶
Overview ¶
Package greenery is a localizable struct annotation based command-line application framework.
Greenery can be used to create localized CLI applications supporting command-line, environment and configuration-file options.
It is an opinionated porcelain built on top of Cobra (https://github.com/spf13/cobra) and Viper (https://github.com/spf13/viper). In greenery, rather than via code, the configuration variables are defined in a single configuration structure, which is mapped to the user-visible variables via golang struct annotations.
User commands are invoked with a configuration structure set to the currently effective configuration, taking into account the command line, the environment and any specified configuration files.
A localizeable documentation functionality is also provided, together with some predefined commands that can be used to generate configuration files that can be used by the application itself.
See https://github.com/woodensquares/greenery for additional usage information.
Index ¶
- Constants
- Variables
- func ConvertOrPanic(unprocessedDocs map[string][]string) map[string]*DocSet
- func FileContents(cfg Config) (string, error)
- type BaseConfig
- func (cfg *BaseConfig) Cleanup()
- func (cfg *BaseConfig) CleanupCallback(override bool, arg any)
- func (cfg *BaseConfig) Custom(s string, l int, val interface{})
- func (cfg *BaseConfig) Customq(s string, l int, val interface{})
- func (cfg *BaseConfig) Customv(s string, l int, val interface{})
- func (cfg *BaseConfig) Debug(s string)
- func (cfg *BaseConfig) Debugf(format string, vals ...interface{})
- func (cfg *BaseConfig) Debugq(s string)
- func (cfg *BaseConfig) Debugqf(format string, vals ...interface{})
- func (cfg *BaseConfig) Debugqs(s string, vals ...LogField)
- func (cfg *BaseConfig) Debugs(s string, vals ...LogField)
- func (cfg *BaseConfig) Debugv(s string)
- func (cfg *BaseConfig) Debugvf(format string, vals ...interface{})
- func (cfg *BaseConfig) Debugvs(s string, vals ...LogField)
- func (cfg *BaseConfig) DisableConsole()
- func (cfg *BaseConfig) Dump(icfg Config) (string, error)
- func (cfg *BaseConfig) Error(s string)
- func (cfg *BaseConfig) Errorf(format string, vals ...interface{})
- func (cfg *BaseConfig) Errors(s string, vals ...LogField)
- func (cfg *BaseConfig) Execute(icfg Config, userDocList map[string]*DocSet) error
- func (cfg *BaseConfig) GenericUnmarshaler(ucfg interface{}, name string, value interface{}) (interface{}, error)
- func (cfg *BaseConfig) GetArgs() []string
- func (cfg *BaseConfig) GetConfigFile() string
- func (cfg *BaseConfig) GetCurrentCommand() string
- func (cfg *BaseConfig) GetDefaultLanguage() string
- func (cfg *BaseConfig) GetDocs() (string, *DocSet)
- func (cfg *BaseConfig) GetFs() afero.Fs
- func (cfg *BaseConfig) GetLocalizedDocsFromDirectory(efs *embed.FS, dir string) (map[string]*DocSet, error)
- func (cfg *BaseConfig) GetLoggers() (Logger, Logger)
- func (cfg *BaseConfig) GetTraceLogger() Logger
- func (cfg *BaseConfig) HideCommand(s string) error
- func (cfg *BaseConfig) Info(s string)
- func (cfg *BaseConfig) Infof(format string, vals ...interface{})
- func (cfg *BaseConfig) Infoq(s string)
- func (cfg *BaseConfig) Infoqf(format string, vals ...interface{})
- func (cfg *BaseConfig) Infoqs(s string, vals ...LogField)
- func (cfg *BaseConfig) Infos(s string, vals ...LogField)
- func (cfg *BaseConfig) Infov(s string)
- func (cfg *BaseConfig) Infovf(format string, vals ...interface{})
- func (cfg *BaseConfig) Infovs(s string, vals ...LogField)
- func (cfg *BaseConfig) MapStructureUnmarshaler(name string, value interface{}, config *mapstructure.DecoderConfig) (interface{}, error)
- func (cfg *BaseConfig) RegisterExtraParsers(m map[string]func(Config, string, interface{}) (interface{}, error))
- func (cfg *BaseConfig) RegisterFinalParser(f func(Config, map[string]interface{}) ([]string, []interface{}, error), ...)
- func (cfg *BaseConfig) SetCleanupCallback(cb func(any), arg any)
- func (cfg *BaseConfig) SetConfigDocumentationSorter(sorter func(vars []*ConfigDocumentationVariable, l, r int) bool)
- func (cfg *BaseConfig) SetFs(fs afero.Fs)
- func (cfg *BaseConfig) SetHandler(handler OverrideHandler, h Handler) error
- func (cfg *BaseConfig) SetLoggers(console, file MakeLogger)
- func (cfg *BaseConfig) SetOptions(opts BaseConfigOptions) error
- func (cfg *BaseConfig) SetTraceLogger(trace MakeLogger, skip int)
- func (cfg *BaseConfig) SetUserCommandHandlers(fmap map[string]Handler) error
- func (cfg *BaseConfig) StartTracing(t *testing.T)
- func (cfg *BaseConfig) StopTracing()
- func (cfg *BaseConfig) TestHelper(task string, value interface{}) interface{}
- func (cfg *BaseConfig) Trace(s string)
- func (cfg *BaseConfig) TraceSkipPlusf(skip int, format string, vals ...interface{})
- func (cfg *BaseConfig) TraceSkipf(format string, vals ...interface{})
- func (cfg *BaseConfig) Tracef(format string, vals ...interface{})
- func (cfg *BaseConfig) Unmarshal(s string, v interface{}) error
- func (cfg *BaseConfig) Warn(s string)
- func (cfg *BaseConfig) Warnf(format string, vals ...interface{})
- func (cfg *BaseConfig) Warns(s string, vals ...LogField)
- type BaseConfigOptions
- type CmdHelp
- type Config
- type ConfigDocumentationVariable
- type ConfigOptions
- type Converter
- type CustomStringHandler
- type CustomStringValue
- func (c *CustomStringValue) GetTyped() string
- func (c *CustomStringValue) MarshalJSON() ([]byte, error)
- func (c *CustomStringValue) MarshalText() ([]byte, error)
- func (c *CustomStringValue) Set(s string) error
- func (c *CustomStringValue) String() string
- func (c *CustomStringValue) Type() string
- func (c *CustomStringValue) UnmarshalText(text []byte) error
- type DocSet
- type EnumValue
- type Handler
- type HelpStrings
- type IPValue
- type IntValue
- func (i *IntValue) GetTyped() int
- func (i *IntValue) MarshalJSON() ([]byte, error)
- func (i *IntValue) MarshalText() ([]byte, error)
- func (i *IntValue) Set(s string) error
- func (i *IntValue) SetInt(d int) error
- func (i *IntValue) String() string
- func (i *IntValue) Type() string
- func (i *IntValue) UnmarshalText(text []byte) error
- type LogField
- func LogDuration(name string, value time.Duration) LogField
- func LogGeneric(name string, id int, value interface{}) LogField
- func LogGenericIDValue(id int, value interface{}) LogField
- func LogGenericValue(value interface{}) LogField
- func LogGenericValues(value ...interface{}) []LogField
- func LogInteger(name string, value int) LogField
- func LogString(name string, value string) LogField
- func LogTime(name string, value time.Time) LogField
- type LogFieldType
- type Logger
- type MakeLogger
- type MakeTraceLogger
- type OverrideHandler
- type PortValue
- func (p *PortValue) GetTyped() uint16
- func (p *PortValue) MarshalJSON() ([]byte, error)
- func (p *PortValue) MarshalText() ([]byte, error)
- func (p *PortValue) Set(e string) error
- func (p *PortValue) SetInt(i int) error
- func (p *PortValue) String() string
- func (p *PortValue) Type() string
- func (p *PortValue) UnmarshalText(text []byte) error
- type ValidationType
- type Validator
Constants ¶
const ( // DocBaseDelimiter is the delimiter to be used for the base section, this // will map to the toplevel of the DocSet struct. DocBaseDelimiter = doc.BaseDelimiter // DocUse contains the text to display in the use line for the application // itself, this is typically used if the root command has a handler which // takes arguments. The text to be used should follow in the next string in // the list. The string following will be assigned to DocSet.Use. DocUse = doc.Use // DocLong is the long description for the application as a whole. The text to // be used should follow in the next string in the list. The string following // will be assigned to DocSet.Long. DocLong = doc.Long // DocShort is the short description for the application as a whole. The text // to be used should follow in the next string in the list.. The string // following will be assigned to DocSet.Short. DocShort = doc.Short // DocExample is an example to be used for the application as a whole. The // text to be used should follow in the next string in the list. . The string // following will be assigned to DocSet.Example. DocExample = doc.Example // DocHelpFlag is the text displayed next to the help command when printing // the help for the application. The text to be used should follow in the next // string. The string following will be assigned to DocSet.HelpFlag. DocHelpFlag = doc.HelpFlag // DocCmdFlags is the text to use for "[flags]" as printed in command help // messages. The text to be used should follow in the next string in the // list. The string following will be assigned to DocSet.CmdFlags. DocCmdFlags = doc.CmdFlags // DocConfigEnvMsg1 is part of the localized text to be used for the config // env command. The text to be used should follow in the next string in the // list. The string following will be assigned to DocSet.ConfigEnvMsg1. DocConfigEnvMsg1 = doc.ConfigEnvMsg1 // DocConfigEnvMsg2 is part of the localized text to be used for the config // env command. The text to be used should follow in the next string in the // list. The string following will be assigned to DocSet.ConfigEnvMsg2. DocConfigEnvMsg2 = doc.ConfigEnvMsg2 // DocConfigEnvMsg3 is part of the localized text to be used for the config // env command. The text to be used should follow in the next string in the // list. The string following will be assigned to DocSet.ConfigEnvMsg3. DocConfigEnvMsg3 = doc.ConfigEnvMsg3 // DocHelpDelimiter is the delimiter of the help section. This will map to the // Help field in the DocSet struct, which is a HelpStrings struct. These // strings will be used to localize the overall common headers/footers/... in // various help messages. DocHelpDelimiter = doc.HelpDelimiter // DocUsage controls the "Usage:" sentence. The text to be used should follow in // the next string in the list. The string following will be assigned to // HelpStrings.Usage. DocUsage = doc.Usage // DocAliases controls the "Aliases:" sentence. The text to be used should // follow in the next string in the list. The string following will be // assigned to HelpStrings.Aliases. DocAliases = doc.Aliases // DocExamples controls the "Examples:" sentence. The text to be used should // follow in the next string in the list. The string following will be assigned to // HelpStrings.Examples. DocExamples = doc.Examples // DocAvailableCommands controls the "Available Commands:" sentence. The text // to be used should follow in the next string in the list. The string // following will be assigned to HelpStrings.AvailableCommands. DocAvailableCommands = doc.AvailableCommands // DocFlags controls the "Flags:" sentence. The text to be used should follow // in the next string in the list. The string following will be assigned to // HelpStrings.Flags. DocFlags = doc.Flags // DocGlobalFlags controls the "Global Flags:" sentence. The text to be used // should follow in the next string in the list. The string following will be // assigned to HelpStrings.GlobalFlags. DocGlobalFlags = doc.GlobalFlags // DocAdditionalHelpTopics controls the "Additional help topics:" // sentence. The text to be used should follow in the next string in the // list. The string following will be assigned to // HelpStrings.AdditionalHelpTopics. DocAdditionalHelpTopics = doc.AdditionalHelpTopics // DocProvidesMoreInformationAboutACommand controls the "provides more // information about a command." sentence. The text to be used should follow // in the next string in the list. The string following will be assigned to // HelpStrings.ProvidesMoreInformationAboutACommand. DocProvidesMoreInformationAboutACommand = doc.ProvidesMoreInformationAboutACommand // DocUsageDelimiter is the delimiter for the usage section, this will map to // the Usage field in the DocSet struct, which is a CmdHelp struct. This is // used to contain help for individual commands, existing and // user-created. Each command is controlled by a sequence of five strings, // they are in order: // // identifier of the command (which is the key in the handlers map, this can // also be one of the predefined identifiers below) // usage string (in case the command has arguments), will map to CmdHelp.Use // short help for the command, will map to CmdHelp.Short // long help for the command, will map to CmdHelp.Long // example for the command, will map to CmdHelp.Example // // Internal commands have predefined constants, so they can be used instead of // writing things like "config>init" which might be confusing for the // localizers. DocUsageDelimiter = doc.UsageDelimiter // DocCompletionCmd is the identifier for the "completion" command. DocCompletionCmd = doc.CompletionCmd // DocCompletionBashCmd is the identifier for the "bash" completion sub-command. DocCompletionBashCmd = doc.CompletionBashCmd // DocCompletionZshCmd is the identifier for the "zsh" completion sub-command. DocCompletionZshCmd = doc.CompletionZshCmd // DocCompletionFishCmd is the identifier for the "fish" completion sub-command. DocCompletionFishCmd = doc.CompletionFishCmd // DocCompletionPowerShellCmd is the identifier for the "powershell" completion sub-command. DocCompletionPowerShellCmd = doc.CompletionPowerShellCmd // DocConfigCmd is the identifier for the "config" command. DocConfigCmd = doc.ConfigCmd // DocConfigInitCmd is the identifier for the "config init" command. DocConfigInitCmd = doc.ConfigInitCmd // DocConfigEnvCmd is the identifier for the "config env" command. DocConfigEnvCmd = doc.ConfigEnvCmd // DocConfigDisplayCmd is the identifier for the "config display" command. DocConfigDisplayCmd = doc.ConfigDisplayCmd // DocHelpCmd is the identifier for the "help" command. DocHelpCmd = doc.HelpCmd // DocVersionCmd is the identifier for the "version" command. DocVersionCmd = doc.VersionCmd // DocCmdlineDelimiter is the delimiter for the command line flags section, // this will map to the CmdLine field in the DocSet struct, which is a map of // strings. In this section the format is simply // // name of the variable corresponding to the flag // help information for this flag to be displayed // // as in the usage section above, predefined identifiers are included for the // base flags defined by the library. DocCmdlineDelimiter = doc.CmdlineDelimiter // DocLogLevel is the help information for the LogLevel flag. DocLogLevel = doc.LogLevel // DocConfFile is the help information for the ConfFile flag. DocConfFile = doc.ConfFile // DocLogFile is the help information for the LogFile flag. DocLogFile = doc.LogFile // DocLogOnlyFile is the help information for the LogOnlyFile flag. DocLogOnlyFile = doc.LogOnlyFile // DocNoEnv is the help information for the NoEnv flag. DocNoEnv = doc.NoEnv // DocNoCfg is the help information for the NoCfg flag. DocNoCfg = doc.NoCfg // DocVerbosity is the help information for the Verbosity flag. DocVerbosity = doc.Verbosity // DocTraceLogFile is the help information for the TraceLogFile flag. DocTraceLogFile = doc.TraceLogFile // DocCfgLocation is the help information for the CfgLocation flag. DocCfgLocation = doc.CfgLocation // DocCfgForce is the help information for the CfgForce flag. DocCfgForce = doc.CfgForce // DocConfigDelimiter is the delimiter for the config file section, this will // map to the ConfigFile field in the DocSet struct, which is a map of // strings. This section has the exact same structure as the Cmdline section // and should contain only entries for which the text between the command line // and config file help is different. In addition it also typically contains // the help displayed for custom configuration sections, the predefined base // section name follows. DocConfigDelimiter = doc.ConfigDelimiter // DocErrorsDelimiter is the delimiter for any error strings in a key/value format. DocErrorsDelimiter = doc.ErrorsDelimiter // DocConfigHeader is the name of the base configuration file section, this is // going to be treated as a golang template, {{ date }} is available and will // be substituted with the date/time the configuration file has been generated // at. DocConfigHeader = doc.ConfigHeader // DocConfigSkip can be set as a description for a configuration variable to prevent // it from being output when initializing a configuration. DocConfigSkip = doc.ConfigSkip // DocCustomDelimiter is the delimiter for the custom file section, this // will map to the Custom field in the DocSet struct, which is a map of // strings. This section is not used by the standard library but is // available for custom string localizations. DocCustomDelimiter = doc.CustomDelimiter )
These constants are to be used when creating string-list user documentation, they contain identifiers used for the section delimiters, as well as for all the individual options.
const ( // LogLevelDebug is the string corresponding to the debug log level. LogLevelDebug = "debug" // LogLevelInfo is the string corresponding to the info log level. LogLevelInfo = "info" // LogLevelWarn is the string corresponding to the warn log level. LogLevelWarn = "warn" // LogLevelError is the string corresponding to the error log level. LogLevelError = "error" )
const ( LogGenericType = iota LogDurationType LogIntType LogStringType LogTimeType )
Variables ¶
var ActiveDocLanguage string
ActiveDocLanguage is set to the current language, it can be used from functions where it is not practical to pass the configuration around (unmarshalers for example).
Functions ¶
func ConvertOrPanic ¶
ConvertOrPanic is used to convert a set of documents from the []string format to the final map[string]*DocSet one, this function will panic in case there are any errors in the conversion.
func FileContents ¶ added in v0.9.2
Types ¶
type BaseConfig ¶
type BaseConfig struct {
// LogLevel maps to the loglevel options, it contains the requested
// logging level. Valid values are available as string constants named
// LogLevelDebug, LogLevelInfo, LogLevelWarn and LogLevelError which
// can then be compared to, if needed, with LogLevel.Value
LogLevel *EnumValue `greenery:"|log-level|l, .log-level, ##!!PROGRAMNAME!!##_LOGLEVEL"`
// ConfFile maps to the config file options, it contains the name of the
// requested configuration file.
ConfFile string `greenery:"|config|c, , ##!!PROGRAMNAME!!##_CONFIGFILE"`
// LogFile maps to the log file options, it contains the name of the
// requested log file.
LogFile string `greenery:"|log-file|, .log-file, ##!!PROGRAMNAME!!##_LOGFILE"`
// LogOnlyFile maps to the log file options, if set, log messages will
// be sent only to the logfile, if present, and not to stdout/stderr
LogOnlyFile bool `greenery:"|log-only-file|, .log-only-file, ##!!PROGRAMNAME!!##_LOGONLYFILE"`
// NoEnv maps to the no-environment options, it contains whether the user
// requested to not consult the environment when setting configuration
// values.
NoEnv bool `greenery:"|no-env|, .no-env,"`
// NoCfg maps to the no-cfg options, it contains whether the
// user requested to not consult the configuration file when setting
// configuration values.
NoCfg bool `greenery:"|no-cfg|, ,##!!PROGRAMNAME!!##_NOCFG"`
// ConfigVersion contains the loaded configuration file version, it can be used through PeekConfig
// to choose the correct user configuration struct to deserialize to for backwards compatibility
// purposes. If no version is set in the configuration file, this will be set to 1.
ConfigVersion int `greenery:"||none, .config-version, "`
// Verbosity maps to the verbosity options, it contains the requested
// level of verbosity.
Verbosity *IntValue `greenery:"|verbosity|v, .verbosity, ##!!PROGRAMNAME!!##_VERBOSITY"`
// TraceLogFile maps to the tracing options, it contains whether the user
// requested tracing output to be written to a tracing log file.
TraceLogFile string `greenery:"|trace-log-file|hidden, , ##!!PROGRAMNAME!!##_TRACE_LOGFILE"`
// CfgForce maps to the --force parameter to the config init command, this
// controls whether an already existing configuration file will be
// overwritten by the command.
CfgForce bool `greenery:"config>init|force|,,"`
// CfgLocation maps to the --location parameter to the config init
// command, this controls where the configuration file is created.
CfgLocation *EnumValue `greenery:"config>init|location|,,"`
// Values users are expected to set as part of their configuration init
// function. Users might need to access these directly in their code
// afterwards (for example to implement version compatibility, or to check
// the default language for error message purposes) so these are public.
//
// For versions VersionFull has precedence over major/minor/patchlevel so
// will be printed instead if set.
// ------------------------------------------------------------------
VersionFull string `greenery:"||none,,"`
VersionMajor string `greenery:"||none,,"`
VersionMinor string `greenery:"||none,,"`
VersionPatchlevel string `greenery:"||none,,"`
// contains filtered or unexported fields
}
BaseConfig is the default base configuration, that needs to be embedded in all user configuration structs. It contains all the needed internal variables as well as exported alues for the built-in configuration values, like the current log level, log file, configuration file name and so on.
func NewBaseConfig ¶
func NewBaseConfig(opts ConfigOptions, fmap map[string]Handler) *BaseConfig
NewBaseConfig returns an initialized BaseConfig struct, it requires the application name and an optional map of handlers for the application commands. Handlers can also be set later with a SetCommandHandlers call.
func PeekConfig ¶ added in v0.9.2
func PeekConfig(opts ConfigOptions) (*BaseConfig, error)
func (*BaseConfig) Cleanup ¶
func (cfg *BaseConfig) Cleanup()
Cleanup should be called at the end of the program, it will close and remove any temporary files, and sync the log. This function is safe to be called multiple times.
func (*BaseConfig) CleanupCallback ¶ added in v0.9.2
func (cfg *BaseConfig) CleanupCallback(override bool, arg any)
CleanupCallback will call the cleanup callback, if configured. This can be useful as part of deferred panic handlers.
func (*BaseConfig) Custom ¶ added in v0.9.2
func (cfg *BaseConfig) Custom(s string, l int, val interface{})
Custom is used to custom log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Customq ¶ added in v0.9.2
func (cfg *BaseConfig) Customq(s string, l int, val interface{})
Customq is used to custom log to the current logger with verbosity 1.
func (*BaseConfig) Customv ¶ added in v0.9.2
func (cfg *BaseConfig) Customv(s string, l int, val interface{})
Customv is used to custom log to the current logger with verbosity 3.
func (*BaseConfig) Debug ¶
func (cfg *BaseConfig) Debug(s string)
Debug is used to debug log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Debugf ¶
func (cfg *BaseConfig) Debugf(format string, vals ...interface{})
Debugf is used to sprintf debug log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Debugq ¶
func (cfg *BaseConfig) Debugq(s string)
Debugq is used to debug log to the current logger with verbosity 1.
func (*BaseConfig) Debugqf ¶
func (cfg *BaseConfig) Debugqf(format string, vals ...interface{})
Debugqf is used to sprintf debug log to the current logger with verbosity 1.
func (*BaseConfig) Debugqs ¶
func (cfg *BaseConfig) Debugqs(s string, vals ...LogField)
Debugqs is used to structured debug log to the current logger with verbosity 1.
func (*BaseConfig) Debugs ¶
func (cfg *BaseConfig) Debugs(s string, vals ...LogField)
Debugs is used to structured debug log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Debugv ¶
func (cfg *BaseConfig) Debugv(s string)
Debugv is used to debug log to the current logger with verbosity 3.
func (*BaseConfig) Debugvf ¶
func (cfg *BaseConfig) Debugvf(format string, vals ...interface{})
Debugvf is used to sprintf debug log to the current logger with verbosity 3.
func (*BaseConfig) Debugvs ¶
func (cfg *BaseConfig) Debugvs(s string, vals ...LogField)
Debugvs is used to structured debug log to the current logger with verbosity 3.
func (*BaseConfig) DisableConsole ¶ added in v0.9.2
func (cfg *BaseConfig) DisableConsole()
DisableConsole disables console logging, this is the same as passing --log-only-file on the command line.
func (*BaseConfig) Dump ¶
func (cfg *BaseConfig) Dump(icfg Config) (string, error)
Dump will print on stdout the current configuration values.
func (*BaseConfig) Error ¶
func (cfg *BaseConfig) Error(s string)
Error is used to error log to the current logger, errors are always logged unless v is 0, so no need to have custom selectable verbosity.
func (*BaseConfig) Errorf ¶
func (cfg *BaseConfig) Errorf(format string, vals ...interface{})
Errorf is used to sprintf error log to the current logger, errors are always logged unless v is 0, so no need to have custom selectable verbosity.
func (*BaseConfig) Errors ¶
func (cfg *BaseConfig) Errors(s string, vals ...LogField)
Errors is used to structured error log to the current logger, errors are always logged unless v is 0, so no need to have custom selectable verbosity.
func (*BaseConfig) Execute ¶
func (cfg *BaseConfig) Execute(icfg Config, userDocList map[string]*DocSet) error
Execute is the main entry point for the library, it requires an initialized configuration struct, as well as the documentation strings to be used for the program.
func (*BaseConfig) GenericUnmarshaler ¶ added in v0.9.2
func (cfg *BaseConfig) GenericUnmarshaler(ucfg interface{}, name string, value interface{}) (interface{}, error)
func (*BaseConfig) GetArgs ¶ added in v0.9.2
func (cfg *BaseConfig) GetArgs() []string
GetArgs returns the original os.Args[] used when the program was called.
func (*BaseConfig) GetConfigFile ¶
func (cfg *BaseConfig) GetConfigFile() string
GetConfigFile returns the filename of the configuration file used.
func (*BaseConfig) GetCurrentCommand ¶
func (cfg *BaseConfig) GetCurrentCommand() string
GetCurrentCommand returns the name of the currently executing command, note that the root/base command is returned as "".
func (*BaseConfig) GetDefaultLanguage ¶
func (cfg *BaseConfig) GetDefaultLanguage() string
GetDefaultLanguage return the default language set in the configuration.
func (*BaseConfig) GetDocs ¶
func (cfg *BaseConfig) GetDocs() (string, *DocSet)
GetDocs returns the current docset in use.
func (*BaseConfig) GetFs ¶
func (cfg *BaseConfig) GetFs() afero.Fs
GetFs returns the filesystem currently in use.
func (*BaseConfig) GetLocalizedDocsFromDirectory ¶ added in v0.9.2
func (cfg *BaseConfig) GetLocalizedDocsFromDirectory(efs *embed.FS, dir string) (map[string]*DocSet, error)
GetLocalizedDocsFromDirectory is used to convert a directory containing text files, one for each language, named LANG.txt (where lang is the language code, so en-US.txt etc.) into a single internal docset for the current locale language.
The file format is the same as the explicit string list format, however, any identifier MUST be surrounded by | characters, and the text format also allows any line between identifiers beginning with # to be treated as a comment.
func (*BaseConfig) GetLoggers ¶ added in v0.9.2
func (cfg *BaseConfig) GetLoggers() (Logger, Logger)
GetLoggers retrieves the currently configured loggers. This will be set by the cfg.Execute handler is called, so it will be available only when commands are executed, not before.
func (*BaseConfig) GetTraceLogger ¶ added in v0.9.2
func (cfg *BaseConfig) GetTraceLogger() Logger
GetTraceLogger retrieves the currently configured trace loggers. This will be set by the cfg.Execute handler is called, so it will be available only when commands are executed, not before.
func (*BaseConfig) HideCommand ¶ added in v0.9.2
func (cfg *BaseConfig) HideCommand(s string) error
HideCommand allows to mark a command as hidden (will not be shown in the help).
func (*BaseConfig) Info ¶
func (cfg *BaseConfig) Info(s string)
Info is used to info log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Infof ¶
func (cfg *BaseConfig) Infof(format string, vals ...interface{})
Infof is used to sprintf info log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Infoq ¶
func (cfg *BaseConfig) Infoq(s string)
Infoq is used to info log to the current logger with verbosity 1.
func (*BaseConfig) Infoqf ¶
func (cfg *BaseConfig) Infoqf(format string, vals ...interface{})
Infoqf is used to sprintf info log to the current logger with verbosity 1.
func (*BaseConfig) Infoqs ¶
func (cfg *BaseConfig) Infoqs(s string, vals ...LogField)
Infoqs is used to send a structured info log to the current logger with verbosity 1.
func (*BaseConfig) Infos ¶
func (cfg *BaseConfig) Infos(s string, vals ...LogField)
Infos is used to structured info log to the current logger with verbosity 2 (typical).
func (*BaseConfig) Infov ¶
func (cfg *BaseConfig) Infov(s string)
Infov is used to info log to the current logger with verbosity 3.
func (*BaseConfig) Infovf ¶
func (cfg *BaseConfig) Infovf(format string, vals ...interface{})
Infovf is used to sprintf info log to the current logger with verbosity 3.
func (*BaseConfig) Infovs ¶
func (cfg *BaseConfig) Infovs(s string, vals ...LogField)
Infovs is used to structured info log to the current logger with verbosity 3.
func (*BaseConfig) MapStructureUnmarshaler ¶ added in v0.9.2
func (cfg *BaseConfig) MapStructureUnmarshaler(name string, value interface{}, config *mapstructure.DecoderConfig) (interface{}, error)
func (*BaseConfig) RegisterExtraParsers ¶ added in v0.9.2
func (cfg *BaseConfig) RegisterExtraParsers(m map[string]func(Config, string, interface{}) (interface{}, error))
RegisterExtraParsers allows custom parsing for variables in the configuration file, see the "custom" example for a usage example.
func (*BaseConfig) RegisterFinalParser ¶ added in v0.9.2
func (cfg *BaseConfig) RegisterFinalParser(f func(Config, map[string]interface{}) ([]string, []interface{}, error), a []string)
RegisterFinalParser allows a final additional parsing for the configuration file, see the "custom" example for a usage example.
func (*BaseConfig) SetCleanupCallback ¶ added in v0.9.2
func (cfg *BaseConfig) SetCleanupCallback(cb func(any), arg any)
SetCleanupCallback sets a function that will be called as part of Cleanup(). Note this will be called before logging is stopped.
func (*BaseConfig) SetConfigDocumentationSorter ¶ added in v0.9.2
func (cfg *BaseConfig) SetConfigDocumentationSorter(sorter func(vars []*ConfigDocumentationVariable, l, r int) bool)
SetConfigDocumentationSorter will set a function that will be in charge of sorting the configuration variables before they are written in the configuration file, when running the config init command. Set to nil to use the default sorter.
func (*BaseConfig) SetFs ¶
func (cfg *BaseConfig) SetFs(fs afero.Fs)
SetFs allows the filesystem used by the library to be set.
func (*BaseConfig) SetHandler ¶
func (cfg *BaseConfig) SetHandler(handler OverrideHandler, h Handler) error
SetHandler allows overriding of the handlers for the built-in base, config and version commands. In addition it allows to set a handler that will be invoked just before passing control to the requested command handler, as well as one that will be invoked before the config file is loaded.
func (*BaseConfig) SetLoggers ¶
func (cfg *BaseConfig) SetLoggers(console, file MakeLogger)
SetLoggers sets the specified loggers creators, if both are set to nil, no logging will be available. If one is set, but the other is not, console and file will get the same information (this is faster than setting both to the same MakeLogger due to reusing the encoding). If both are set, each will use their specific MakeLogger for encoding purposes.
func (*BaseConfig) SetOptions ¶
func (cfg *BaseConfig) SetOptions(opts BaseConfigOptions) error
SetOptions allows setting configuration options before the Execute call is made.
func (*BaseConfig) SetTraceLogger ¶ added in v0.9.2
func (cfg *BaseConfig) SetTraceLogger(trace MakeLogger, skip int)
SetTraceLogger sets the logger to be used for trace logging. If set to nil trace logging will not be available at all even if requested on the command-line.
func (*BaseConfig) SetUserCommandHandlers ¶ added in v0.9.2
func (cfg *BaseConfig) SetUserCommandHandlers(fmap map[string]Handler) error
SetUserCommandHandlers allows setting command handlers after the base struct is created, but before it is executed.
func (*BaseConfig) StartTracing ¶
func (cfg *BaseConfig) StartTracing(t *testing.T)
StartTracing is used to start trace logging. This can be force-enabled during testing without a tracing log file set by passing the t parameter.
func (*BaseConfig) StopTracing ¶
func (cfg *BaseConfig) StopTracing()
StopTracing is used to stop trace logging.
func (*BaseConfig) TestHelper ¶
func (cfg *BaseConfig) TestHelper(task string, value interface{}) interface{}
TestHelper is used by tests to change some internals if needed. Callers must know what they are doing as there is little/no error checking.
func (*BaseConfig) Trace ¶
func (cfg *BaseConfig) Trace(s string)
Trace is used to debug log only to the trace logger, if tracing is active.
func (*BaseConfig) TraceSkipPlusf ¶ added in v0.9.2
func (cfg *BaseConfig) TraceSkipPlusf(skip int, format string, vals ...interface{})
TraceSkipPlusf will tracef log but skipping additional frames in case .Trace is being passed around as a function. This function allows adjusting the configured trace skip value.
func (*BaseConfig) TraceSkipf ¶
func (cfg *BaseConfig) TraceSkipf(format string, vals ...interface{})
TraceSkipf will tracef log but skipping additional frames in case .Trace is being passed around as a function.
func (*BaseConfig) Tracef ¶
func (cfg *BaseConfig) Tracef(format string, vals ...interface{})
Tracef is used to sprintf debug log to the trace logger, if tracing is active.
func (*BaseConfig) Unmarshal ¶
func (cfg *BaseConfig) Unmarshal(s string, v interface{}) error
Unmarshal allows unmarshalling of a single configuration key, if that key type is supported by the underlying TOML library. See the "custom" example for a usage example.
func (*BaseConfig) Warn ¶
func (cfg *BaseConfig) Warn(s string)
Warn is used to warn log to the current logger, warnings are always logged unless v is 0, so no need to have custom selectable verbosity.
func (*BaseConfig) Warnf ¶
func (cfg *BaseConfig) Warnf(format string, vals ...interface{})
Warnf is used to sprintf warn log to the current logger, warnings are always logged unless v is 0, so no need to have custom selectable verbosity.
func (*BaseConfig) Warns ¶
func (cfg *BaseConfig) Warns(s string, vals ...LogField)
Warns is used to structured warn log to the current logger, warnings are always logged unless v is 0, so no need to have custom selectable verbosity.
type BaseConfigOptions ¶
type BaseConfigOptions struct {
DefaultLanguage string
VersionFull string
VersionMajor string
VersionMinor string
VersionPatchlevel string
}
BaseConfigOptions can be used to set the same-named variables in a configuration to the specified values. DefaultLanguage will be ignored if empty, version strings will be assigned as-is.
type CmdHelp ¶
type CmdHelp struct {
// Use contains the use information for the command, if it takes arguments
Use string
// Short contains the short documentation for the command, typically
// displayed in the parent command's help
Short string
// Long contains the long documentation for the command
Long string
// Example contains any examples for this command
Example string
}
CmdHelp contains the Cobra use/short/long/example documentation strings in a particular language.
type Config ¶
type Config interface {
Cleanup()
CleanupCallback(override bool, arg any)
SetCleanupCallback(cb func(any), arg any)
DisableConsole()
Dump(cfg Config) (string, error)
Execute(cfg Config, docset map[string]*DocSet) error
GetArgs() []string
GetConfigFile() string
GetCurrentCommand() string
GetDefaultLanguage() string
GetDocs() (string, *DocSet)
GetFs() afero.Fs
RegisterExtraParsers(parsers map[string]func(Config, string, interface{}) (interface{}, error))
RegisterFinalParser(parser func(Config, map[string]interface{}) ([]string, []interface{}, error), vals []string)
SetFs(fs afero.Fs)
SetHandler(override OverrideHandler, handler Handler) error
SetUserCommandHandlers(handlers map[string]Handler) error
SetOptions(opt BaseConfigOptions) error
SetLoggers(consoleLogger MakeLogger, fileLogger MakeLogger)
GetLoggers() (Logger, Logger)
SetTraceLogger(logger MakeLogger, skip int)
GetTraceLogger() Logger
Unmarshal(key string, val interface{}) error
Customq(format string, lvl int, fields interface{})
Custom(format string, lvl int, fields interface{})
Customv(format string, lvl int, fields interface{})
Debugq(msg string)
Debugqf(format string, fields ...interface{})
Debugqs(format string, fields ...LogField)
Debug(msg string)
Debugf(format string, fields ...interface{})
Debugs(format string, fields ...LogField)
Debugv(msg string)
Debugvf(format string, fields ...interface{})
Debugvs(format string, fields ...LogField)
Infoq(msg string)
Infoqf(format string, fields ...interface{})
Infoqs(format string, fields ...LogField)
Info(msg string)
Infof(format string, fields ...interface{})
Infos(format string, fields ...LogField)
Infov(msg string)
Infovf(format string, fields ...interface{})
Infovs(format string, fields ...LogField)
Warn(msg string)
Warnf(format string, fields ...interface{})
Warns(format string, fields ...LogField)
Error(msg string)
Errorf(format string, fields ...interface{})
Errors(format string, fields ...LogField)
StartTracing(t *testing.T)
StopTracing()
Trace(msg string)
Tracef(format string, fields ...interface{})
// TestHelper is used by tests only to tweak internals as needed.
TestHelper(task string, value interface{}) interface{}
// contains filtered or unexported methods
}
Config is the interface fulfilled by a configuration struct that can be used by the greenery library. It is a sealed interface and can be fulfilled only by BaseConfig structs, or structs embedding it. See the documentation in BaseStruct for more information on the individual methods.
type ConfigDocumentationVariable ¶ added in v0.9.2
type ConfigOptions ¶ added in v0.9.2
type CustomStringHandler ¶
CustomStringHandler defines a function used to validate the custom string for correctness. This function will be passed, in order, the name of this flag, the value the user would like to set, and the arbitrary flag data. The function should return the value that will be set in the flag, which could be different from what the user sends, and an error if the value is not acceptable.
type CustomStringValue ¶
type CustomStringValue struct {
Value string
// contains filtered or unexported fields
}
CustomStringValue is a flag struct that has a customizeable validator / converter.
func NewCustomStringValue ¶
func NewCustomStringValue(name string, validate CustomStringHandler, data interface{}) *CustomStringValue
NewCustomStringValue returns a new CustomStringValue flag, the default value is set to whatever the validation function will return when passed the empty string. Name is a name for this flag, typically the configuration variable name, and is used for error messages. Data is arbitrary data that will be stored in the flag and passed to the custom validation function on validation calls.
func NewDefaultCustomStringValue ¶
func NewDefaultCustomStringValue(name string, set string, validate CustomStringHandler, data interface{}) *CustomStringValue
NewDefaultCustomStringValue returns a new CustomStringValue flag with the initial value being what the validation function will return when passed the string specified in set. Name is a name for this flag, typically the configuration variable name, and is used for error messages. Data is arbitrary data that will be stored in the flag and passed to the custom validation function on validation calls. If the set value does not fulfill the validate function, this function will panic.
func (*CustomStringValue) GetTyped ¶
func (c *CustomStringValue) GetTyped() string
GetTyped is typically used for tests and returns the flag string value.
func (*CustomStringValue) MarshalJSON ¶ added in v0.9.2
func (c *CustomStringValue) MarshalJSON() ([]byte, error)
MarshalJSON can be used if, say, the user marshaled the configuration file to json for debugging purposes.
func (*CustomStringValue) MarshalText ¶
func (c *CustomStringValue) MarshalText() ([]byte, error)
MarshalText is used for TOML configuration file marshaling, it is used when generating the config files via config generate.
func (*CustomStringValue) Set ¶
func (c *CustomStringValue) Set(s string) error
Set will set the string value, while validating for correctness by calling the custom validation function, if set.
func (*CustomStringValue) String ¶
func (c *CustomStringValue) String() string
String will return the string flag value.
func (*CustomStringValue) Type ¶
func (c *CustomStringValue) Type() string
Type will return a string describing the type of the flag, it is required to fulfill pflag.Value and will be printed in the help messages.
func (*CustomStringValue) UnmarshalText ¶
func (c *CustomStringValue) UnmarshalText(text []byte) error
UnmarshalText is used for TOML configuration file unmarshalling, and will set the value in the flag with validation.
type DocSet ¶
type DocSet struct {
// Use contains a string appended to the application name, when displaying
// the help for the root command. It can be useful, for example, if a
// positional parameter is used in the application: for example if the
// application is named "tester" and it is going to support a URI of the
// site to test as a parameter, this string could be set to "[website
// address]".
Use string
// Short contains the short description for the program (displayed for the
// root command).
Short string
// Long contains the short description for the program (displayed for the
// root command).
Long string
// Example contains usage examples for the command.
Example string
// HelpFlag contains the help string displayed in the root command help
// for the --help help flag.
HelpFlag string
// CmdFlags contains the string corresponding to [flags] which is printed
// after the command in the usage line if required.
CmdFlags string
// ConfigEnvMsg1 contains the first part of the localizable message for
// the config env command.
ConfigEnvMsg1 string
// ConfigEnvMsg2 contains the second part of the localizable message for
// the config env command.
ConfigEnvMsg2 string
// ConfigEnvMsg3 contains the third and final part of the localizable
// message for the config env command.
ConfigEnvMsg3 string
// Help points to a struct that contains the strings used in the help
// template itself (things like "Aliases:" etc.).
Help *HelpStrings
// CmdLine contains the doc strings displayed in each command-line flag,
// for the specified configuration file variable. This map is keyed by the
// file variable name.
CmdLine map[string]string
// ConfigFile contains the doc strings that will be put in the
// autogenerated configuration file before each configuration file
// variable. This map is also keyed by the configuration file variable
// name. These will be automatically commented when put in the TOML
// configuration file unless they refer to a variable with a custom
// deserialization, in which case they will be printed as-is in order to
// allow providing of arbitrary default values.
ConfigFile map[string]string
// Usage contains the command-specific usage information, the key is the
// command name as defined in the command map that is passed to Execute.
Usage map[string]*CmdHelp
// Errors contains error strings.
Errors map[string]string
// Custom contains user-supplied localized strings.
Custom map[string]string
}
DocSet contains the config documentation for a specific language.
var ActiveDocs *DocSet
ActiveDocs is set to the current DocSet, it can be used from functions where it is not practical to pass the configuration around (unmarshalers for example).
func ConvertDocs ¶
ConvertDocs is used to convert a []string documentation to the internal *DocSet representation, it will return an error if there are any parsing issues. Note the code can't be super precise in the validation given a single list of strings with arbitrary names, it tries to catch at least obvious things like multiple sections or wrong number of lines in a section etc.
type EnumValue ¶
type EnumValue struct {
*CustomStringValue
}
EnumValue is a CustomStringValue flag struct containing, and validating for, a specified set of acceptable string values set on creation.
func NewDefaultEnumValue ¶
NewDefaultEnumValue returns a new EnumValue flag, its value is set to the passed set value. Name is a name for this flag, typically the configuration variable name, and is used for error messages. valid is a set of valid values for this flag, at least one must be present. If the set value is not a valid enum value this function will panic.
func NewEnumValue ¶
NewEnumValue returns a new EnumValue flag, its value is set to the first value in the valid enums list. Name is a name for this flag, typically the configuration variable name, and is used for error messages. valid is a set of valid values for this flag, at least one must be present.
type Handler ¶
Handler is the user-provided function that will be called by the library when the specified command is selected. It will be passed the current configuration, as well as a list of command-line arguments.
type HelpStrings ¶
type HelpStrings struct {
// Usage contains the localized "Usage:" sentence
Usage string
// Aliases contains the localized "Aliases:" sentence
Aliases string
// Examples contains the localized "Examples:" sentence
Examples string
// AvailableCommands contains the localized "Available Commands:" sentence
AvailableCommands string
// Flags contains the localized "Flags:" sentence
Flags string
// GlobalFlags contains the localized "Global Flags:" sentence
GlobalFlags string
// AdditionalHelpTopics contains the localized "Additional help topics:"
// sentence
AdditionalHelpTopics string
// ProvidesMoreInformationAboutACommand contains the localized "provides
// more information about a command." sentence
ProvidesMoreInformationAboutACommand string
}
HelpStrings contains the strings used for the various portions of the template.
type IPValue ¶
type IPValue struct {
*CustomStringValue
}
IPValue is a CustomStringValue flag struct containing, and validating for, an IP address (v4 or v6).
func NewDefaultIPValue ¶
NewDefaultIPValue returns a new IPValue flag set to the passed set value. Name is a name for this flag, typically the configuration variable name, and is used for error messages. If the set value is not a valid IP, this function will panic.
func NewIPValue ¶
NewIPValue returns a new IPValue flag, its value is set to "0.0.0.0". Name is a name for this flag, typically the configuration variable name, and is used for error messages.
type IntValue ¶
type IntValue struct {
Value int
// contains filtered or unexported fields
}
IntValue is a flag struct containing an integer with customizeable minimum and maximum values.
func NewDefaultIntValue ¶
func NewDefaultIntValue(name string, set, mmin, mmax int, vt ValidationType) *IntValue
NewDefaultIntValue returns a new IntValue flag set to the specified "set" value. Name is a name for this flag, typically the configuration variable name, and is used for error messages. Min and max are the values to be used as min/max values to validate against. v is the ValidationType to use for the validation.
func NewIntValue ¶
func NewIntValue(name string, mmin, mmax int, vt ValidationType) *IntValue
NewIntValue returns a new IntValue flag, its initial value is set to min. Name is a name for this flag, typically the configuration variable name, and is used for error messages. Min and max are the values to be used as min/max values to validate against. vt is the ValidationType to use for the validation.
func (*IntValue) MarshalJSON ¶ added in v0.9.2
MarshalJSON can be used if, say, the user marshaled the configuration file to json for debugging purposes.
func (*IntValue) MarshalText ¶
MarshalText is used for TOML configuration file marshaling, it is used when generating the config files via config generate.
func (*IntValue) Set ¶
Set will set a value parsing from a string, while validating for correctness.
func (*IntValue) Type ¶
Type will return a string describing the type of the flag, it is required to fulfill pflag.Value and will be printed in the help messages.
func (*IntValue) UnmarshalText ¶
UnmarshalText is used for TOML configuration file unmarshalling, and will set the value in the flag with validation.
type LogField ¶
type LogField struct {
Key string
Type LogFieldType
Integer int
Time time.Time
Duration time.Duration
String string
GenericID int
Generic interface{}
}
func LogDuration ¶ added in v0.9.2
LogDuration returns a greenery LogField for a time.Duration logging value.
func LogGeneric ¶ added in v0.9.2
LogGeneric returns a greenery LogField for a generic logging value, with a name and an ID.
func LogGenericIDValue ¶ added in v0.9.2
LogGenericIDValue returns a greenery LogField for a generic logging value with an ID, but no name.
func LogGenericValue ¶ added in v0.9.2
func LogGenericValue(value interface{}) LogField
LogGenericValue returns a greenery LogField for a generic logging value.
func LogGenericValues ¶ added in v0.9.2
func LogGenericValues(value ...interface{}) []LogField
LogGenericValues returns an array greenery LogField for generic logging values.
func LogInteger ¶ added in v0.9.2
LogInteger returns a greenery LogField for an int logging value.
type LogFieldType ¶ added in v0.9.2
type LogFieldType int
LogField is used by the structured logging functions to pass around information about the specific field. Each logger can decide how to use these fields as they see fit.
type Logger ¶
type Logger interface {
Custom(format string, level int, fields interface{})
TraceCustom(format string, fields interface{})
TraceStructured(format string, fields ...LogField)
DebugStructured(format string, fields ...LogField)
InfoStructured(format string, fields ...LogField)
WarnStructured(format string, fields ...LogField)
ErrorStructured(format string, fields ...LogField)
Sync() error
// DebugSkip is used for testing purposes.
DebugSkip(skip int, msg string)
}
Logger is an interface that describes a logger provided by logger.go, currently this is just a basic printf logger. A zap logger is available in zaplogger/ if a structured or more high performant logger is required.
func BaseLogger ¶ added in v0.9.2
BaseLogger represents a base logger used for normal logging.
type MakeLogger ¶
MakeLogger describes a function that would return a normal logger.
type MakeTraceLogger ¶
MakeTraceLogger describes a function that would return a trace logger.
type OverrideHandler ¶
type OverrideHandler int
OverrideHandler allows to select which internal command to override in calls to SetHandler.
const ( // OverrideRootHandler selects the root command. OverrideRootHandler OverrideHandler = iota // OverrideConfigHandler selects the config command. OverrideConfigHandler // OverrideVersionHandler selects the version command. OverrideVersionHandler // OverridePreLoadHandler allows a handler that will be executed before the // configuration file is loaded. OverridePreLoadHandler // OverridePreExecHandler allows a handler that will be executed before the // actual command handler. OverridePreExecHandler )
type PortValue ¶
type PortValue uint16
PortValue is a flag representing a port value, from 0 to 65535. An IntValue flag with these limits could have also been used, either directly or as an embedded struct.
func NewPortValue ¶
func NewPortValue() PortValue
NewPortValue returns a new PortValue flag, its value is set to 0.
func (*PortValue) GetTyped ¶
GetTyped is typically used for tests and returns the flag uint16 value.
func (*PortValue) MarshalJSON ¶ added in v0.9.2
MarshalJSON can be used if, say, the user marshaled the configuration file to json for debugging purposes.
func (*PortValue) MarshalText ¶
MarshalText is used for TOML configuration file marshaling, it is used when generating the config files via config generate.
func (*PortValue) Set ¶
Set will set a value parsing from a string, while validating for correctness.
func (*PortValue) Type ¶
Type will return a string describing the type of the flag, it is required to fulfill pflag.Value and will be printed in the help messages.
func (*PortValue) UnmarshalText ¶
UnmarshalText is used for TOML configuration file unmarshalling, and will set the value in the flag with validation.
type ValidationType ¶ added in v0.9.2
type ValidationType int
ValidationType is what validation is required for this particular value, can be set to ValidationNone, ValidationLow, ValidationHigh or ValidationLowHigh to respectively not validate, validate the lower bound, the upper bound, or both bounds. If the limits are valid values ValidationLowEqual, ValidationHighEqual and ValidationLowEqualHigh, ValidationLowHighEqual or ValidationLowEqualHighEqual can be used.
const ( ValidationNone ValidationType = iota ValidationLow ValidationLowEqual ValidationHigh ValidationHighEqual ValidationLowEqualHigh ValidationLowHighEqual ValidationLowHigh ValidationLowEqualHighEqual )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
demos
|
|
|
custom
command
|
|
|
localized-code
command
|
|
|
localized-files
command
|
|
|
minimal
command
|
|
|
multiple-versions
command
|
|
|
internal
|
|
|
Package greenery/testhelper is a helper library used to test greenery-based applications.
|
Package greenery/testhelper is a helper library used to test greenery-based applications. |
|
Package greenery/zapbackend is a sample zap logging back-end for greenery based applications.
|
Package greenery/zapbackend is a sample zap logging back-end for greenery based applications. |