optional

package module
v2.0.0-...-af4d38d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

optional

随意的处理数据

数据处理模型

optional_model

  • value
  • processor
  • validator
  • align
设计思路
  • value和type存储数据类型和值,附加函数处理数据类型转换。
  • processor处理数据
  • validator验证数据
  • align反射赋值到指定字段
扩展功能
  • 类型与值: 添加多个数据来源接口,添加json序列化实现,添加国际化错误返回接口
  • 处理器: 完善更多的处理器函数,添加自定义处理器接口,优化处理器执行
  • 验证器:完善更多的验证起函数,添加自定义验证起接口,优化验证逻辑
  • 赋值: 完善反射赋值,添加多种赋值方式。

友情链接

Documentation

Index

Constants

View Source
const (
	FmtMustNotNil          = "%s filed value must is not nil"
	FmtMustTrue            = "%s filed value must is true"
	FmtMustHasSuffix       = "%s filed value must has %s suffix"
	FmtMustString          = "%s filed value must is a string type"
	FmtMustHasString       = "%s filed value must has %s string value"
	FmtMustHasSymbol       = "%s filed value must has symbol"
	FmtMustHasDigit        = "%s filed value must has digit"
	FmtMustHasLetter       = "%s filed value must has letter"
	FmtMustHasLower        = "%s filed value must has lower"
	FmtMustHasUpper        = "%s filed value must has upper"
	FmtMustIn              = "%s filed value must in %value upper"
	FmtMustEquals          = "%s filed value must equals %s"
	FmtMustIsLower         = "%s filed value must is lower"
	FmtMustIsUpper         = "%s filed value must is upper"
	FmtMustIsLetter        = "%s filed value must is letter"
	FmtMustIsDigit         = "%s filed value must is digit"
	FmtMustIsLowerOrDigit  = "%s filed value must is lower or digit"
	FmtMustIsUpperOrDigit  = "%s filed value must is upper or digit"
	FmtMustIsLetterOrDigit = "%s filed value must is letter or digit"
	FmtMustIsChinese       = "%s filed value must is chinese"
	FmtMustIsUUID          = "%s filed value must is uuid"
	FmtMustIsSQLObject     = "%s filed value must is sql "
	FmtMustIsIp            = "%s filed value must is ip "
	FmtMustIsNumber        = "%s filed value must is number type"
)

Variables

View Source
var ConvertError = errors.New("This type conversion is not supported")
View Source
var NilVal = Value{
	// contains filtered or unexported fields
}

Functions

func Align

func Align(name string, a interface{}) align

func Process

func Process(name string, apply ...Apply) processor

func ToCamelCase

func ToCamelCase(s string) string

func ToPascalCase

func ToPascalCase(s string) string

func ToSnakeCase

func ToSnakeCase(s string) string

func Validate

func Validate(name string, matches ...Match) validator

Types

type Apply

type Apply func(val *processor) error

func Base64StdEncode

func Base64StdEncode() Apply

func RemoveSpace

func RemoveSpace() Apply

func ToInt

func ToInt() Apply

func ToUpper

func ToUpper() Apply

func Trim

func Trim(s string) Apply

type Belief

type Belief interface {
	GetError() error

	Value() Value
}

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type Match

type Match func(val *validator) error

func MustEquals

func MustEquals(s string) Match

func MustHasDigit

func MustHasDigit() Match

func MustHasLetter

func MustHasLetter() Match

func MustHasLower

func MustHasLower() Match

func MustHasString

func MustHasString(s string) Match

func MustHasSuffix

func MustHasSuffix(s string) Match

func MustHasSymbol

func MustHasSymbol() Match

func MustHasUpper

func MustHasUpper() Match

func MustIn

func MustIn(s []string) Match

func MustIsChinaMobile

func MustIsChinaMobile() Match

func MustIsChinese

func MustIsChinese() Match

func MustIsDigit

func MustIsDigit() Match

func MustIsEmail

func MustIsEmail() Match

func MustIsIP

func MustIsIP() Match

func MustIsJSON

func MustIsJSON() Match

func MustIsLetter

func MustIsLetter() Match

func MustIsLetterOrDigit

func MustIsLetterOrDigit() Match

func MustIsLower

func MustIsLower() Match

func MustIsLowerOrDigit

func MustIsLowerOrDigit() Match

func MustIsNumberValue

func MustIsNumberValue() Match

func MustIsSQLObject

func MustIsSQLObject() Match

func MustIsURL

func MustIsURL() Match

func MustIsUUID

func MustIsUUID() Match

func MustIsUpper

func MustIsUpper() Match

func MustIsUpperOrDigit

func MustIsUpperOrDigit() Match

func MustNotNil

func MustNotNil() Match

func MustString

func MustString() Match

func MustTrue

func MustTrue() Match

type Type

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

Type represents value types within the type system.

This is a closed interface type, meaning that only the concrete implementations provided within this package are considered valid.

var Bool Type
var Float32 Type
var Float64 Type
var Int Type
var Int16 Type
var Int32 Type
var Int64 Type
var Int8 Type
var String Type
var Uint Type
var Uint16 Type
var Uint32 Type
var Uint64 Type
var Uint8 Type

func StringMap

func StringMap() Type

func StringMapType

func StringMapType(ty map[string]Type) Type

func (Type) Equals

func (t Type) Equals(other Type) bool

func (Type) FriendlyName

func (t Type) FriendlyName() string

func (Type) GetStringMapType

func (t Type) GetStringMapType(key string) (Type, error)

func (Type) GoString

func (t Type) GoString() string

func (Type) IsMapType

func (t Type) IsMapType() bool

func (Type) IsPrimitiveType

func (t Type) IsPrimitiveType() bool

func (Type) Len

func (t Type) Len() int

func (Type) UpdateAttrType

func (t Type) UpdateAttrType(ty map[string]Type) error

type Value

type Value struct {
	// contains filtered or unexported fields
}
var False Value
var NegativeInfinity Value
var PositiveInfinity Value
var True Value
var Zero Value

func BoolVal

func BoolVal(v bool) Value

BoolVal returns a Value of type Number whose internal value is the given bool.

func Float32Val

func Float32Val(v float32) Value

func Float64Val

func Float64Val(v float64) Value

func HttpRequestBodyVal

func HttpRequestBodyVal(req *http.Request) Value

func HttpRequestFormVal

func HttpRequestFormVal(req *http.Request) Value

func HttpRequestQueryVal

func HttpRequestQueryVal(req *http.Request) Value

func Int16Val

func Int16Val(v int16) Value

func Int32Val

func Int32Val(v int32) Value

func Int64Val

func Int64Val(v int64) Value

func Int8Val

func Int8Val(v int8) Value

func IntVal

func IntVal(v int) Value

func MapStringVal

func MapStringVal(vals map[string]Value) Value

func MapStringValEmpty

func MapStringValEmpty() Value

func NullVal

func NullVal(t Type) Value

NullVal returns a null value of the given type. A null can be created of any type, but operations on such values will always panic. Calling applications are encouraged to use nulls only sparingly, particularly when user-provided expressions are to be evaluated, since the precence of nulls creates a much higher chance of evaluation errors that can't be caught by a type checker.

func ParseFloat64Val

func ParseFloat64Val(s string) (Value, error)

ParseNumberVal returns a Value of type number produced by parsing the given string as a decimal real number. To ensure that two identical strings will always produce an equal number, always use this function to derive a number from a string; it will ensure that the precision and rounding mode for the internal big decimal is configured in a consistent way.

If the given string cannot be parsed as a number, the returned error has the message "a number is required", making it suitable to return to an end-user to signal a type conversion error.

If the given string contains a number that becomes a recurring fraction when expressed in binary then it will be truncated to have a 512-bit mantissa. Note that this is a higher precision than that of a float64, so coverting the same decimal number first to float64 and then calling NumberFloatVal will not produce an equal result; the conversion first to float64 will round the mantissa to fewer than 512 bits.

func StringVal

func StringVal(v string) Value

StringVal returns a Value of type String whose internal value is the given string.

Strings must be UTF-8 encoded sequences of valid unicode codepoints, and they are NFC-normalized on entry into the world of cty values.

If the given string is not valid UTF-8 then behavior of string operations is undefined.

func Uint16Val

func Uint16Val(v uint16) Value

func Uint32Val

func Uint32Val(v uint32) Value

func Uint64Val

func Uint64Val(v uint64) Value

func Uint8Val

func Uint8Val(v uint8) Value

func UintVal

func UintVal(v uint) Value

func (Value) Align

func (val Value) Align(a align) error

func (Value) Aligns

func (val Value) Aligns(aligns ...align) error

验证结果后直接赋值

func (Value) Converter

func (val Value) Converter() converter

func (Value) Equals

func (val Value) Equals(v Value) bool

func (Value) GetError

func (val Value) GetError() error

func (Value) GetErrorResponseWriter

func (val Value) GetErrorResponseWriter(resp http.ResponseWriter) error

func (Value) GetMapValue

func (val Value) GetMapValue(name string) Value

func (Value) IsMapValue

func (val Value) IsMapValue() bool

func (Value) IsNull

func (val Value) IsNull() bool

func (Value) IsPrimitiveValue

func (val Value) IsPrimitiveValue() bool

func (Value) Processor

func (val Value) Processor(name string, apply ...Apply) processor

func (Value) Processors

func (val Value) Processors(ps ...processor) processors

func (Value) SetMapValue

func (val Value) SetMapValue(name string, value Value) Value

func (Value) String

func (val Value) String() string

func (Value) StringProcessor

func (val Value) StringProcessor() stringProcessor

func (Value) Type

func (val Value) Type() Type

func (Value) UnMarshal

func (val Value) UnMarshal(v interface{}) error

func (Value) Validate

func (val Value) Validate(name string, match ...Match) validator

func (Value) Validates

func (val Value) Validates(validates ...validator) validators

func (Value) Value

func (val Value) Value() Value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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