Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReformatDialsTagSource ¶
func ReformatDialsTagSource(inner dials.Source, encodeFunc caseconversion.DecodeCasingFunc, decodeFunc caseconversion.EncodeCasingFunc) dials.Source
ReformatDialsTagSource is a convenience function that provides a source that first reformats `dials` tags on the passed type for a dials config struct, changing the casing as specified (e.g., from lowerCamelCase into snake_case), then calls Value on the wrapped source with the modified struct type passed in.
Types ¶
type TagCopyingMangler ¶
type TagCopyingMangler struct {
SrcTag, NewTag string
}
TagCopyingMangler implements the transform.Mangler interface copying `SrcTag` tags unmodified into a new tag specified by the `NewTag` member, for example `json` or `yaml`. It is intended to be used by `dials.Decoder`s which need to make use of those tags. To change the casing of tags, use a dialsTagReformattingSource.
func (*TagCopyingMangler) Mangle ¶
func (t *TagCopyingMangler) Mangle(sf reflect.StructField) ([]reflect.StructField, error)
Mangle is called for every field in a struct, and maps that to one or more output fields. Implementations that desire to leave fields unchanged should return the argument unchanged. (particularly useful if taking advantage of recursive evaluation)
func (*TagCopyingMangler) ShouldRecurse ¶
func (t *TagCopyingMangler) ShouldRecurse(_ reflect.StructField) bool
ShouldRecurse is called after Mangle for each field so nested struct fields get iterated over after any transformation done by Mangle(). This ShouldRecurse always returns true here so inner struct tags get appropriately mangled.
func (*TagCopyingMangler) Unmangle ¶
func (t *TagCopyingMangler) Unmangle(sf reflect.StructField, vs []transform.FieldValueTuple) (reflect.Value, error)
Unmangle is called for every source-field->mangled-field mapping-set, with the mangled-field and its populated value set. This just returns the first field, as Mangle only returns one field at a time.
type TagReformattingMangler ¶
type TagReformattingMangler struct {
// contains filtered or unexported fields
}
TagReformattingMangler implements transform.Mangler, rewriting the specified struct tag (with Mangler recursion enabled)
func NewTagReformattingMangler ¶
func NewTagReformattingMangler(tagName string, enc caseconversion.DecodeCasingFunc, dec caseconversion.EncodeCasingFunc) *TagReformattingMangler
NewTagReformattingMangler constructs a new TagReformattingMangler that can replace the value of an existing tag
func (*TagReformattingMangler) Mangle ¶
func (k *TagReformattingMangler) Mangle(sf reflect.StructField) ([]reflect.StructField, error)
Mangle is called for every field in a struct, and returns the value unchanged other than replacing the specified tag.
func (*TagReformattingMangler) ShouldRecurse ¶
func (k *TagReformattingMangler) ShouldRecurse(_ reflect.StructField) bool
ShouldRecurse is called after Mangle for each field so nested struct fields get iterated over after any transformation done by Mangle().
func (*TagReformattingMangler) Unmangle ¶
func (k *TagReformattingMangler) Unmangle(sf reflect.StructField, vs []transform.FieldValueTuple) (reflect.Value, error)
Unmangle is called for every source-field->mangled-field mapping-set, with the mangled-field and its populated value set. The implementation of Unmangle should return a reflect.Value that will be used for the next mangler or final struct value)