Documentation ¶
Overview ¶
the configer is not thread safe, make sure not use it after call process.Start()
Index ¶
- Constants
- Variables
- func AddFlags(fs *pflag.FlagSet)
- func Envs() []string
- func FlagSet(fs *pflag.FlagSet, sample interface{}, opts ...ConfigFieldsOption) error
- func Flags() []string
- func ToFloat64Slice(str string) []float64
- func ToFloat64SliceE(i interface{}) ([]float64, error)
- func ToIntSlice(str string) []int
- func ToString(v interface{}) string
- func ToStringArrayVar(str string) []string
- func ToStringMapString(str string) map[string]string
- func ValueFiles() []string
- func Var(fs *pflag.FlagSet, path string, sample interface{}, opts ...ConfigFieldsOption) error
- func WithConfiger(parent context.Context, cf ParsedConfiger) context.Context
- type ConfigFields
- type ConfigFieldsOption
- type Configer
- type ConfigerOption
- func WithDefault(path string, sample interface{}) ConfigerOption
- func WithDefaultYaml(path, yaml string) ConfigerOption
- func WithEnv(allowEnv, allowEmptyEnv bool) ConfigerOption
- func WithMaxDepth(maxDepth int) ConfigerOption
- func WithOverride(path string, sample interface{}) ConfigerOption
- func WithOverrideYaml(path, yaml string) ConfigerOption
- func WithValueFile(valueFiles ...string) ConfigerOption
- type ConfigerOptions
- type ErrNoTable
- type ErrNoValue
- type FieldTag
- type ParsedConfiger
- type ReleaseOptions
- type Values
Examples ¶
Constants ¶
const GlobalKey = "global"
GlobalKey is the name of the Values key that is used for storing global vars.
Variables ¶
var (
DefaultConfiger = NewConfiger()
)
Functions ¶
func FlagSet ¶ added in v0.0.2
func FlagSet(fs *pflag.FlagSet, sample interface{}, opts ...ConfigFieldsOption) error
just for cmdcli
func ToFloat64Slice ¶ added in v0.0.2
func ToFloat64SliceE ¶ added in v0.0.2
ToFloat64SliceE casts an interface to a []time.Duration type.
func ToIntSlice ¶ added in v0.0.2
func ToStringArrayVar ¶ added in v0.0.2
func ToStringMapString ¶ added in v0.0.2
func ValueFiles ¶
func ValueFiles() []string
func Var ¶ added in v0.0.2
func Var(fs *pflag.FlagSet, path string, sample interface{}, opts ...ConfigFieldsOption) error
Var set config fields to yaml configfile reader and pflags.FlagSet from sample
func WithConfiger ¶ added in v0.0.2
func WithConfiger(parent context.Context, cf ParsedConfiger) context.Context
Types ¶
type ConfigFields ¶ added in v0.0.2
type ConfigFields struct {
// contains filtered or unexported fields
}
type ConfigFieldsOption ¶
type ConfigFieldsOption func(*configFieldsOptions)
func WithTags ¶
func WithTags(getter func() map[string]*FieldTag) ConfigFieldsOption
WithTags just for AddConfigs
type Configer ¶
type Configer interface { Var(fs *pflag.FlagSet, path string, sample interface{}, opts ...ConfigFieldsOption) error Parse(opts ...ConfigerOption) (ParsedConfiger, error) AddFlags(fs *pflag.FlagSet) ValueFiles() []string Envs() []string Flags() []string }
func NewConfiger ¶
func NewConfiger() Configer
type ConfigerOption ¶
type ConfigerOption func(*ConfigerOptions)
func WithDefault ¶
func WithDefault(path string, sample interface{}) ConfigerOption
with config object
func WithEnv ¶
func WithEnv(allowEnv, allowEmptyEnv bool) ConfigerOption
func WithMaxDepth ¶
func WithMaxDepth(maxDepth int) ConfigerOption
func WithOverride ¶
func WithOverride(path string, sample interface{}) ConfigerOption
func WithOverrideYaml ¶
func WithOverrideYaml(path, yaml string) ConfigerOption
func WithValueFile ¶
func WithValueFile(valueFiles ...string) ConfigerOption
WithValueFile priority greater than --values
type ConfigerOptions ¶
type ConfigerOptions struct {
// contains filtered or unexported fields
}
func (*ConfigerOptions) Validate ¶
func (p *ConfigerOptions) Validate() error
type ErrNoTable ¶
type ErrNoTable struct {
Key string
}
ErrNoTable indicates that a chart does not have a matching table.
func (ErrNoTable) Error ¶
func (e ErrNoTable) Error() string
type ErrNoValue ¶
type ErrNoValue struct {
Key string
}
ErrNoValue indicates that Values does not contain a key with a value
func (ErrNoValue) Error ¶
func (e ErrNoValue) Error() string
type FieldTag ¶
type FieldTag struct { Flag []string // flag:"{long},{short}" Arg string // arg:"{arg}" args[0] arg1... -- arg2... (deprecated) Default string // default:"{default}" Env string // env:"{env}" Description string // description:"{description}" Deprecated string // deprecated:"" // contains filtered or unexported fields }
func GetFieldTag ¶
func GetFieldTag(sf reflect.StructField) (tag *FieldTag)
type ParsedConfiger ¶ added in v0.0.2
type ParsedConfiger interface { ValueFiles() []string Envs() []string Flags() []string //FlagSet() *pflag.FlagSet Set(path string, v interface{}) error GetConfiger(path string) ParsedConfiger GetRaw(path string) interface{} GetString(path string) string GetBool(path string) (bool, error) GetBoolDef(path string, def bool) bool GetFloat64(path string) (float64, error) GetFloat64Def(path string, def float64) float64 GetInt64(path string) (int64, error) GetInt64Def(path string, def int64) int64 GetInt(path string) (int, error) GetIntDef(path string, def int) int IsSet(path string) bool Read(path string, into interface{}) error String() string }
func ConfigerFrom ¶ added in v0.0.2
func ConfigerFrom(ctx context.Context) (ParsedConfiger, bool)
func ConfigerMustFrom ¶ added in v0.0.2
func ConfigerMustFrom(ctx context.Context) ParsedConfiger
func Parse ¶ added in v0.0.2
func Parse(opts ...ConfigerOption) (ParsedConfiger, error)
Example ¶
package main import ( "fmt" "github.com/yubo/golib/configer" ) type User struct { Name string `flag:"name"` } func main() { c, err := configer.NewConfiger().Parse() fmt.Printf("%s", c) fmt.Printf("%v", err) }
Output: {} <nil>
type ReleaseOptions ¶
type ReleaseOptions struct { Name string Namespace string Revision int IsUpgrade bool IsInstall bool }
ReleaseOptions represents the additional release options needed for the composition of the final values struct
type Values ¶
type Values map[string]interface{}
Values represents a collection of chart values.
func ReadValues ¶
ReadValues will parse YAML byte data into a Values.
func ReadValuesFile ¶
ReadValuesFile will parse a YAML file into a map of values.
func (Values) AsMap ¶
AsMap is a utility function for converting Values to a map[string]interface{}.
It protects against nil map panics.
func (Values) PathValue ¶
PathValue takes a path that traverses a YAML structure and returns the value at the end of that path. The path starts at the root of the YAML structure and is comprised of YAML keys separated by periods. Given the following YAML data the value at path "chapter.one.title" is "Loomings".
chapter: one: title: "Loomings"