Documentation ¶
Index ¶
- func B2s(b []byte) string
- func Bind(req *protocol.Request, obj interface{}, pathParams param.Params) error
- func BindAndValidate(req *protocol.Request, obj interface{}, pathParams param.Params) error
- func MustRegTypeUnmarshal(t reflect.Type, fn func(v string, emptyAsZero bool) (reflect.Value, error))
- func MustRegValidateFunc(funcName string, fn func(args ...interface{}) error, force ...bool)
- func S2b(s string) (b []byte)
- func SetErrorFactory(bindErrFactory, validatingErrFactory func(failField, msg string) error)
- func SetLooseZeroMode(enable bool)
- func UseGJSONUnmarshaler()
- func UseStdJSONUnmarshaler()
- func UseThirdPartyJSONUnmarshaler(unmarshaler func(data []byte, v interface{}) error)
- func Validate(obj interface{}) error
- type Binder
- func (b *Binder) Bind(request *protocol.Request, i interface{}, params param.Params) error
- func (b *Binder) BindAndValidate(request *protocol.Request, i interface{}, params param.Params) error
- func (b *Binder) BindForm(request *protocol.Request, i interface{}) error
- func (b *Binder) BindHeader(request *protocol.Request, i interface{}) error
- func (b *Binder) BindJSON(request *protocol.Request, i interface{}) error
- func (b *Binder) BindPath(request *protocol.Request, i interface{}, params param.Params) error
- func (b *Binder) BindProtobuf(request *protocol.Request, i interface{}) error
- func (b *Binder) BindQuery(request *protocol.Request, i interface{}) error
- func (b *Binder) Name() string
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func B2s ¶
B2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
Note it may break if string and/or slice header will change in the future go versions.
func BindAndValidate ¶
BindAndValidate binds data from *protocol.Request to obj and validates them if needed. NOTE:
obj should be a pointer.
func MustRegTypeUnmarshal ¶
func MustRegTypeUnmarshal(t reflect.Type, fn func(v string, emptyAsZero bool) (reflect.Value, error))
MustRegTypeUnmarshal registers unmarshal function of type. NOTE:
It will panic if exist error. MustRegTypeUnmarshal will remain in effect once it has been called.
func MustRegValidateFunc ¶
MustRegValidateFunc registers validator function expression. NOTE:
If force=true, allow to cover the existed same funcName. MustRegValidateFunc will remain in effect once it has been called.
func S2b ¶
S2b converts string to a byte slice without memory allocation.
Note it may break if string and/or slice header will change in the future go versions.
func SetErrorFactory ¶
SetErrorFactory customizes the factory of validation error. NOTE:
If errFactory==nil, the default is used. SetErrorFactory will remain in effect once it has been called.
func SetLooseZeroMode ¶
func SetLooseZeroMode(enable bool)
SetLooseZeroMode if set to true, the empty string request parameter is bound to the zero value of parameter. NOTE:
The default is false. Suitable for these parameter types: query/header/cookie/form .
func UseGJSONUnmarshaler ¶
func UseGJSONUnmarshaler()
UseGJSONUnmarshaler uses github.com/bytedance/go-tagexpr/v2/binding/gjson as json library NOTE:
UseGJSONUnmarshaler will remain in effect once it has been called.
func UseStdJSONUnmarshaler ¶
func UseStdJSONUnmarshaler()
UseStdJSONUnmarshaler uses encoding/json as json library NOTE:
The current version uses encoding/json by default. UseStdJSONUnmarshaler will remain in effect once it has been called.
func UseThirdPartyJSONUnmarshaler ¶
UseThirdPartyJSONUnmarshaler uses third-party json library for binding NOTE:
UseThirdPartyJSONUnmarshaler will remain in effect once it has been called.
Types ¶
type Binder ¶
func (*Binder) BindAndValidate ¶
func (*Binder) BindHeader ¶
func (*Binder) BindProtobuf ¶
type Validator ¶
func NewValidator ¶
func NewValidator() *Validator