Documentation
¶
Overview ¶
Package envtag provides tools to parse tags from strings or struct fields.
Index ¶
Constants ¶
View Source
const ( EnvKey = "env" DefaultKey = "default" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldNameNormalizer ¶ added in v0.4.0
type FieldNameNormalizer struct {
// contains filtered or unexported fields
}
FieldNameNormalizer normalizes struct field names to a format that is commonly used in environment variables, e.g. MyFieldName becomes MY_FIELD_NAME.
func (*FieldNameNormalizer) Normalize ¶ added in v0.4.0
func (n *FieldNameNormalizer) Normalize(fieldName, prefix string) string
type Normalizer ¶ added in v0.4.0
type NormalizerFunc ¶ added in v0.4.0
func (NormalizerFunc) Normalize ¶ added in v0.4.0
func (fn NormalizerFunc) Normalize(fieldName, prefix string) string
type Options ¶ added in v0.4.0
type Options struct {
// EnvKey is used to look up the env tag string from a [reflect.StructTag].
EnvKey string
// DefaultKey is used to look up the default value string from a
// [reflect.StructTag].
DefaultKey string
// Normalizer is used to normalize a [reflect.StructField]'s name
// when no name is provided in the env tag string.
Normalizer Normalizer
// StrictTags ignores fields that do not have an env tag when set to true.
StrictTags bool
}
func DefaultOptions ¶ added in v0.4.0
func DefaultOptions() Options
DefaultOptions returns an Options with default values.
type Tag ¶
type Tag struct {
// Name of the tag which will be used to construct the environment
// variable's full name.
Name string
// Default is an optional default value for the field.
Default string
// Ignore indicates the field should be ignored.
Ignore bool
// Inline indicates the field will be "flattened" when it is a struct. This
// means it's child fields will be treated as if they are part of the parent
// struct.
Inline bool
// Include indicates the structs child fields should be included, even if
// they do not have an env tag and Options.StrictTag is set to true.
Include bool
}
func ParseStructField ¶ added in v0.4.0
ParseStructField uses the field's reflect.StructTag to look up the tag string according to the provided Options. It will always return a usable Tag, even if an error has occurred.
func ParseTag ¶
ParseTag parses str into a Tag. It will always return a usable Tag, even if an error has occurred.
func (Tag) DefaultValue ¶ added in v0.5.0
func (Tag) ShouldIgnore ¶ added in v0.4.0
ShouldIgnore indicates if Tag should be ignored.
Click to show internal directories.
Click to hide internal directories.