Documentation ¶
Index ¶
- func FieldSet(field *Field, v string) error
- func StructName(s interface{}) string
- func ToSnakeCase(str string) string
- type DefaultTagLoader
- type EnvironmentLoader
- type Field
- func (f *Field) Fields() []*Field
- func (f *Field) IsExported() bool
- func (f *Field) IsZero() bool
- func (f *Field) Kind() reflect.Kind
- func (f *Field) Name() string
- func (f *Field) Set(val interface{}) error
- func (f *Field) Tag(key string) string
- func (f *Field) TagLookup(key string) (string, bool)
- func (f *Field) Value() interface{}
- type JSONLoader
- type Loader
- type RequiredValidator
- type SFConfig
- type Validator
- type YAMLLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldSet ¶
FieldSet sets field value from the given string value. It converts the string value in a sane way and is useful or environment variables or flags which are by nature in string types.
func StructName ¶
func StructName(s interface{}) string
func ToSnakeCase ¶
Types ¶
type DefaultTagLoader ¶
type DefaultTagLoader struct { // DefaultTagName is the default tag name for struct fields to define // default values for a field. DefaultTagName string }
func (*DefaultTagLoader) Load ¶
func (t *DefaultTagLoader) Load(s interface{}) error
type EnvironmentLoader ¶
type EnvironmentLoader struct { // Prefix prepends given string to every environment variable // FIELDNAME will be {PREFIX}_FIELDNAME Prefix string // CamelCase adds a separator for field names in camelcase form. A // fieldname of "AccessKey" would generate an environment name of // "{PREFIX}_ACCESSKEY". If CamelCase is enabled, the environment name // will be generated in the form of "{PREFIX}_ACCESS_KEY" CamelCase bool EnvTagName string }
func (*EnvironmentLoader) Load ¶
func (e *EnvironmentLoader) Load(s interface{}) error
Load loads the source into the config defined by struct s
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func StructFields ¶
func StructFields(s interface{}) []*Field
func (*Field) Fields ¶
Fields returns a slice of Fields. This is particular handy to get the fields of a nested struct. It panics if field is not exported or if field's kind is not struct
func (*Field) IsExported ¶
IsExported returns true if the given field is exported.
func (*Field) IsZero ¶
IsZero returns true if the given field is not initialized (has a zero value). It panics if the field is not exported.
func (*Field) Set ¶
Set sets the field to given value v. It returns an error if the field is not settable (not addressable or not exported) or if the given value's type doesn't match the fields type.
type JSONLoader ¶
func (*JSONLoader) Load ¶
func (j *JSONLoader) Load(s interface{}) error
Load loads the source into the config defined by struct s. Defaults to using the Reader if provided, otherwise tries to read from the file
type Loader ¶
type Loader interface { // Load loads the source into the config defined by struct s Load(s interface{}) error }
type RequiredValidator ¶
type RequiredValidator struct { // TagName holds the validator tag name. The default is "required" TagName string // TagValue holds the expected value of the validator. The default is "true" TagValue string }
func (*RequiredValidator) Validate ¶
func (e *RequiredValidator) Validate(s interface{}) error
Validate validates the given struct against field's zero values. If intentionally, the value of a field is `zero-valued`(e.g false, 0, "") required tag should not be set for that field.
type SFConfig ¶
type SFConfig struct {
// contains filtered or unexported fields
}
func NewDefaultConfig ¶
func (*SFConfig) AddValidator ¶
func (*SFConfig) MustValidate ¶
func (c *SFConfig) MustValidate(conf interface{})
type Validator ¶
type Validator interface { // Validate validates the config struct Validate(s interface{}) error }
type YAMLLoader ¶
YAMLLoader satisfies the loader interface. It loads the configuration from the given yaml file.
func (*YAMLLoader) Load ¶
func (y *YAMLLoader) Load(s interface{}) error
Load loads the source into the config defined by struct s. Defaults to using the Reader if provided, otherwise tries to read from the file