types

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ValidateTag = "validate"

	StringMinLenKey string = "min_len"
	StringMaxLenKey string = "max_len"

	NumberMinKey string = "min"
	NumberMaxKey string = "max"

	ArrayMinItemsKey string = "min_items"
	ArrayMaxItemsKey string = "max_items"
	ArrayItemKey     string = "item"

	PointerNullableKey string = "nullable"
	PointerNotNullKey  string = "not_null"

	InterfaceFuncKey string = "func"

	StructFuncKey string = "func"

	MapMinItemsKey string = "min_items"
	MapMaxItemsKey string = "max_items"
	MapKeyKey      string = "key"
	MapValueKey    string = "value"
)
View Source
const Array string = "array"
View Source
const Bool string = "bool"
View Source
const Byte string = "byte"
View Source
const FieldNameFromStructDefinition = ""
View Source
const Map string = "map"
View Source
const String string = "string"

Variables

View Source
var ErrUnusedTag = errors.New("unused tag")

Functions

func NewArray

func NewArray(inner TypeDef) *typeArray

func NewBool

func NewBool() *typeBool

func NewByte

func NewByte() *typeByte

func NewChan

func NewChan() *typeChan

func NewCustom

func NewCustom(fieldName string, typeExpr ast.Expr) *typeCustom

func NewExternalCustom

func NewExternalCustom(typeName string, typeExpr ast.Expr) *typeCustom

func NewFunc

func NewFunc() *typeFunc

func NewInterface

func NewInterface() *typeInterface

func NewMap

func NewMap(key, value TypeDef) *typeMap

func NewNumber

func NewNumber(typeName string) *typeNumber

func NewString

func NewString() *typeString

func ParseTags

func ParseTags(astTag *ast.BasicLit, logCtx string) ([]ValidatableTag, FieldTagsNames)

Types

type FieldTagsNames

type FieldTagsNames map[string]string

contains {"json": "provider_id", "xml": "provider_id"} for `json:"provider_id,omitempty" "xml":"provider_id" validate:"min_len=1"

func (FieldTagsNames) Get

func (n FieldTagsNames) Get(name string) string

func (FieldTagsNames) GetFromStructDefinition

func (n FieldTagsNames) GetFromStructDefinition() string

type GenConfig

type GenConfig struct {
	NeedValidatableCheck bool
	SeveralErrors        bool
	SupportedTags        []string
	AddImport            func(string)
}

type Name

type Name struct {
	// contains filtered or unexported fields
}

func NewIndexedKeyName

func NewIndexedKeyName(labelName, indexVar, validateVar, tagName string) Name

func NewIndexedValueName

func NewIndexedValueName(labelName, indexVar, validateVar, tagName string) Name

func NewName

func NewName(pointerPrefix, structVar, labelName, fieldName, tagName string) Name

func NewSimpleNameWithAliasType

func NewSimpleNameWithAliasType(fieldName, aliasType string) Name

func (Name) FieldName

func (n Name) FieldName() string

func (Name) Full

func (n Name) Full() string

func (Name) LabelName

func (n Name) LabelName() string

func (Name) WithAlias

func (n Name) WithAlias() string

func (Name) WithPointer

func (n Name) WithPointer() Name

func (Name) WithoutPointer

func (n Name) WithoutPointer() string

type ScopeTag

type ScopeTag struct {
	Name      string
	InnerTags []ValidatableTag
}

func (ScopeTag) Key

func (t ScopeTag) Key() string

type SimpleTag

type SimpleTag struct {
	Name  string
	Param string
}

func (SimpleTag) Key

func (t SimpleTag) Key() string

type TypeDef

type TypeDef interface {
	Type() string
	SetValidateTag(ValidatableTag) error
	Validate() error
	NeedGenerate() bool
	Generate(w io.Writer, cfg GenConfig, name Name)
	Expr() ast.Expr
}

type TypePointer

type TypePointer struct {
	// contains filtered or unexported fields
}

func NewPointer

func NewPointer(inner TypeDef) *TypePointer

func (*TypePointer) Expr

func (t *TypePointer) Expr() ast.Expr

func (*TypePointer) Generate

func (t *TypePointer) Generate(w io.Writer, cfg GenConfig, name Name)

func (TypePointer) NeedGenerate

func (t TypePointer) NeedGenerate() bool

func (*TypePointer) SetInnerType

func (t *TypePointer) SetInnerType(newType TypeDef) *TypePointer

func (*TypePointer) SetValidateTag

func (t *TypePointer) SetValidateTag(tag ValidatableTag) error

func (*TypePointer) Type

func (t *TypePointer) Type() string

func (*TypePointer) Validate

func (t *TypePointer) Validate() error

type ValidatableTag

type ValidatableTag interface {
	// Key returns a tag title
	Key() string
}

ValidatableTag represents a tag that uses for validating

type ValidatableTags

type ValidatableTags []ValidatableTag

ValidatableTags represents a set of ValidatableTag

func (ValidatableTags) ContainsTag

func (ts ValidatableTags) ContainsTag(t ValidatableTag) bool

ContainsTag checks whether ValidatableTags contains a ValidatableTag

func (ValidatableTags) Empty

func (ts ValidatableTags) Empty() bool

Empty check whether ValidatableTags is empty

Jump to

Keyboard shortcuts

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