structtag

package
v1.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UndTag = "und"
	// The field must be required(Some or Defined).
	// mutually exclusive to nullish, def, null, und.
	// UndTagValueRequired can be combined with len (there's no point though).
	UndTagValueRequired = "required"
	// The field must be nullish(None, Null, Undefined).
	// mutually exclusive to required, def, null, und.
	// UndTagValueNullish can be combined with len.
	UndTagValueNullish = "nullish"
	// The field is allowed to be Some or Defined.
	// can be combined with null, und or len.
	UndTagValueDef = "def"
	// The field is allowed to be None or Null.
	// can be combined with def, und or len.
	UndTagValueNull = "null"
	// The field is allowed to be None or Undefined.
	// can be combined with def, null or len.
	UndTagValueUnd = "und"
	// Only for elastic types.
	//
	// The value must be formatted as len==n, len>n, len>=n, len<n or len<=n,
	// where n is unsigned integer.
	// The field's length will be evaluated as (length) (comparison operator) (n),
	// e.g. if tag is len>12, field.Len() > 12 must return true.
	//
	// can be combined with other options.
	UndTagValueLen = "len"
	// Only for elastic types.
	//
	// The value must be formatted as values:nonnull.
	//
	// nonnull value means its internal value must not have null.
	UndTagValueValues = "values"
)

Variables

View Source
var (
	// ErrNotStruct would be returned by ValidateUnd and CheckUnd
	// if input is not a struct nor a pointer to a struct.
	ErrNotStruct = errors.New("not struct")
	// ErrMultipleOption would be returned by ValidateUnd and CheckUnd
	// if input's `und` struct tags have multiple mutually exclusive options.
	ErrMultipleOption = errors.New("multiple option")
	// ErrUnknownOption is an error value which will be returned by ValidateUnd and CheckUnd
	// if an input has unknown options in `und` struct tag.
	ErrUnknownOption = errors.New("unknown option")
	// ErrMalformedLen is an error which will be returned by ValidateUnd and CheckUnd
	// if an input has malformed len option in `und` struct tag.
	ErrMalformedLen = errors.New("malformed len")
	// ErrMalformedLen is an error which will be returned by ValidateUnd and CheckUnd
	// if an input has malformed values option in `und` struct tag.
	ErrMalformedValues = errors.New("malformed values")
)

Functions

This section is empty.

Types

type ElasticLike

type ElasticLike interface {
	UndLike
	Len() int
	HasNull() bool
}

type LenValidator

type LenValidator struct {
	Len int
	Op  lenOp
}

func ParseLen

func ParseLen(s string) (LenValidator, error)

func (LenValidator) String

func (v LenValidator) String() string

func (LenValidator) Valid

func (v LenValidator) Valid(e ElasticLike) bool

type OptionLike

type OptionLike interface {
	IsNone() bool
	IsSome() bool
}

type States

type States struct {
	Def  bool
	Null bool
	Und  bool
	// contains filtered or unexported fields
}

func (States) String

func (s States) String() string

func (States) Valid

func (s States) Valid(u UndLike) bool

type UndLike

type UndLike interface {
	IsDefined() bool
	IsNull() bool
	IsUndefined() bool
}

type UndOpt

type UndOpt struct {
	States option.Option[States]
	Len    option.Option[LenValidator]
	Values option.Option[ValuesValidator]
}

func ParseOption

func ParseOption(s string) (UndOpt, error)

func (UndOpt) String

func (o UndOpt) String() string

func (UndOpt) Ty

func (o UndOpt) Ty()

func (UndOpt) ValidElastic

func (o UndOpt) ValidElastic(e ElasticLike) bool

func (UndOpt) ValidOpt

func (o UndOpt) ValidOpt(opt OptionLike) bool

func (UndOpt) ValidUnd

func (o UndOpt) ValidUnd(u UndLike) bool

type ValuesValidator

type ValuesValidator struct {
	Nonnull bool
}

func ParseValues

func ParseValues(s string) (ValuesValidator, error)

func (ValuesValidator) String

func (v ValuesValidator) String() string

func (ValuesValidator) Valid

func (v ValuesValidator) Valid(e ElasticLike) bool

Jump to

Keyboard shortcuts

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