Documentation ¶
Index ¶
- Variables
- func HasValue(field reflect.Value) bool
- type ErrInvalidTag
- type ErrInvalidTransformValue
- type ErrInvalidTransformation
- type ErrUndefinedTag
- type Func
- type StructLevelFunc
- type Transformer
- func (t *Transformer) Field(ctx context.Context, v interface{}, tags string) (err error)
- func (t *Transformer) Register(tag string, fn Func)
- func (t *Transformer) RegisterAlias(alias, tags string)
- func (t *Transformer) RegisterStructLevel(fn StructLevelFunc, types ...interface{})
- func (t *Transformer) SetTagName(tagName string)
- func (t *Transformer) Struct(ctx context.Context, v interface{}) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidDive describes an invalid dive tag configuration ErrInvalidDive = errors.New("Invalid dive tag configuration") // ErrUndefinedKeysTag describes an undefined keys tag when and endkeys tag defined ErrUndefinedKeysTag = errors.New("'" + endKeysTag + "' tag encountered without a corresponding '" + keysTag + "' tag") // ErrInvalidKeysTag describes a misuse of the keys tag ErrInvalidKeysTag = errors.New("'" + keysTag + "' tag must be immediately preceeded by the '" + diveTag + "' tag") )
Functions ¶
Types ¶
type ErrInvalidTag ¶
type ErrInvalidTag struct {
// contains filtered or unexported fields
}
ErrInvalidTag defines a bad value for a tag being used
func (*ErrInvalidTag) Error ¶
func (e *ErrInvalidTag) Error() string
Error returns the InvalidTag error text
type ErrInvalidTransformValue ¶
type ErrInvalidTransformValue struct {
// contains filtered or unexported fields
}
An ErrInvalidTransformValue describes an invalid argument passed to Struct or Var. (The argument passed must be a non-nil pointer.)
func (*ErrInvalidTransformValue) Error ¶
func (e *ErrInvalidTransformValue) Error() string
type ErrInvalidTransformation ¶
type ErrInvalidTransformation struct {
// contains filtered or unexported fields
}
ErrInvalidTransformation describes an invalid argument passed to `Struct` or `Field`
func (*ErrInvalidTransformation) Error ¶
func (e *ErrInvalidTransformation) Error() string
Error returns ErrInvalidTransformation message
type ErrUndefinedTag ¶
type ErrUndefinedTag struct {
// contains filtered or unexported fields
}
ErrUndefinedTag defines a tag that does not exist
func (*ErrUndefinedTag) Error ¶
func (e *ErrUndefinedTag) Error() string
Error returns the UndefinedTag error text
type StructLevelFunc ¶
StructLevelFunc accepts all values needed for struct level validation
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer is the base controlling object which contains all necessary information
func New ¶
func New() *Transformer
New creates a new Transform object with default tag name of 'mold'
func (*Transformer) Field ¶
func (t *Transformer) Field(ctx context.Context, v interface{}, tags string) (err error)
Field applies the provided transformations against the variable
func (*Transformer) Register ¶
func (t *Transformer) Register(tag string, fn Func)
Register adds a transformation with the given tag
NOTES: - if the key already exists, the previous transformation function will be replaced. - this method is not thread-safe it is intended that these all be registered before hand
func (*Transformer) RegisterAlias ¶
func (t *Transformer) RegisterAlias(alias, tags string)
RegisterAlias registers a mapping of a single transform tag that defines a common or complex set of transformations to simplify adding transforms to structs.
NOTE: this function is not thread-safe it is intended that these all be registered before hand
func (*Transformer) RegisterStructLevel ¶
func (t *Transformer) RegisterStructLevel(fn StructLevelFunc, types ...interface{})
RegisterStructLevel registers a StructLevelFunc against a number of types. Why does this exist? For structs for which you may not have access or rights to add tags too, from other packages your using.
NOTES: - this method is not thread-safe it is intended that these all be registered prior to any validation
func (*Transformer) SetTagName ¶
func (t *Transformer) SetTagName(tagName string)
SetTagName sets the given tag name to be used. Default is "trans"