Documentation ¶
Index ¶
- func ConfigToYaml(conf interface{}) (b []byte, err error)
- func IsHelpError(err error) bool
- func MustConfigToYaml(conf interface{}) []byte
- type ParseOption
- type Tool
- func (t *Tool) GetViper() *viper.Viper
- func (t *Tool) MustParse(out interface{}, opts ...ParseOption)
- func (t *Tool) Parse(out interface{}, opts ...ParseOption) error
- func (t *Tool) WithCommandLineSupport(args []string) ParseOption
- func (t *Tool) WithCommandLineSupportPathFlag() ParseOption
- func (t *Tool) WithConfigFileSupport(configDir string, filename string) ParseOption
- func (t *Tool) WithConfigFileSupportPathFlag(confFlag string) ParseOption
- func (t *Tool) WithDefaultValueSupport() ParseOption
- func (t *Tool) WithEnvSupport(envPrefix string) ParseOption
- func (t *Tool) WithEnvSupportPathFlag(envPrefix string, envFlag string) ParseOption
- func (t *Tool) WithValidateSupport() ParseOption
- type ToolOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigToYaml ¶
ConfigToYaml converts config to yaml
func IsHelpError ¶
IsHelpError return true if err is command line -h error
func MustConfigToYaml ¶
func MustConfigToYaml(conf interface{}) []byte
MustConfigToYaml converts config to yaml, if failed, panic
Types ¶
type ParseOption ¶
type ParseOption interface { Before(sv *viper.Viper, config interface{}) error After(sv *viper.Viper, config interface{}) error }
ParseOption for tool.Parse()
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool is used to parse config
func (*Tool) MustParse ¶
func (t *Tool) MustParse(out interface{}, opts ...ParseOption)
MustParse parse config, if error, exit program
func (*Tool) Parse ¶
func (t *Tool) Parse(out interface{}, opts ...ParseOption) error
Parse parse config
func (*Tool) WithCommandLineSupport ¶
func (t *Tool) WithCommandLineSupport(args []string) ParseOption
WithCommandLineSupport add commandline support for config parser
func (*Tool) WithCommandLineSupportPathFlag ¶
func (t *Tool) WithCommandLineSupportPathFlag() ParseOption
WithCommandLineSupportPathFlag add commandline support for config parser
func (*Tool) WithConfigFileSupport ¶
func (t *Tool) WithConfigFileSupport(configDir string, filename string) ParseOption
WithConfigFileSupport add config file for config parser
func (*Tool) WithConfigFileSupportPathFlag ¶
func (t *Tool) WithConfigFileSupportPathFlag(confFlag string) ParseOption
WithConfigFileSupportPathFlag add config file for config parser, add context if enable flag mode
func (*Tool) WithDefaultValueSupport ¶
func (t *Tool) WithDefaultValueSupport() ParseOption
WithDefaultValueSupport add default value support for config parser
func (*Tool) WithEnvSupport ¶
func (t *Tool) WithEnvSupport(envPrefix string) ParseOption
WithEnvSupport add env support for config parser
func (*Tool) WithEnvSupportPathFlag ¶
func (t *Tool) WithEnvSupportPathFlag(envPrefix string, envFlag string) ParseOption
WithEnvSupportPathFlag add env support for config parser, add context if enable flag mode
func (*Tool) WithValidateSupport ¶
func (t *Tool) WithValidateSupport() ParseOption
WithValidateSupport adds support to validate parsed config validate grammer ref https://github.com/asaskevich/govalidator
type ToolOption ¶
type ToolOption func(*Tool)
ToolOption option for construct Tool
func WithPathFlagMode ¶
func WithPathFlagMode(args []string) ToolOption
WithPathFlagMode enable path flag mode