tagformat

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

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

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

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

NewTagReformattingMangler constructs a new TagReformattingMangler that can replace the value of an existing tag

func (*TagReformattingMangler) Mangle

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

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL