go_tagexpr

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B2s

func B2s(b []byte) string

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 Bind

func Bind(req *protocol.Request, obj interface{}, pathParams param.Params) error

Bind binds data from *protocol.Request to obj. NOTE:

obj should be a pointer.

func BindAndValidate

func BindAndValidate(req *protocol.Request, obj interface{}, pathParams param.Params) error

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

func MustRegValidateFunc(funcName string, fn func(args ...interface{}) error, force ...bool)

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

func S2b(s string) (b []byte)

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

func SetErrorFactory(bindErrFactory, validatingErrFactory func(failField, msg string) error)

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

func UseThirdPartyJSONUnmarshaler(unmarshaler func(data []byte, v interface{}) error)

UseThirdPartyJSONUnmarshaler uses third-party json library for binding NOTE:

UseThirdPartyJSONUnmarshaler will remain in effect once it has been called.

func Validate

func Validate(obj interface{}) error

Validate validates obj with "vd" tag NOTE:

obj should be a pointer.
Validate should be called after Bind.

Types

type Binder

type Binder struct {
	*binding.Binding
}

func NewBinder

func NewBinder() *Binder

func (*Binder) Bind

func (b *Binder) Bind(request *protocol.Request, i interface{}, params param.Params) error

func (*Binder) BindAndValidate

func (b *Binder) BindAndValidate(request *protocol.Request, i interface{}, params param.Params) error

func (*Binder) BindForm

func (b *Binder) BindForm(request *protocol.Request, i interface{}) error

func (*Binder) BindHeader

func (b *Binder) BindHeader(request *protocol.Request, i interface{}) error

func (*Binder) BindJSON

func (b *Binder) BindJSON(request *protocol.Request, i interface{}) error

func (*Binder) BindPath

func (b *Binder) BindPath(request *protocol.Request, i interface{}, params param.Params) error

func (*Binder) BindProtobuf

func (b *Binder) BindProtobuf(request *protocol.Request, i interface{}) error

func (*Binder) BindQuery

func (b *Binder) BindQuery(request *protocol.Request, i interface{}) error

func (*Binder) Name

func (b *Binder) Name() string

type Validator

type Validator struct {
	*binding.Binding
}

func NewValidator

func NewValidator() *Validator

func (*Validator) Engine

func (v *Validator) Engine() interface{}

func (*Validator) ValidateStruct

func (v *Validator) ValidateStruct(i interface{}) error

func (*Validator) ValidateTag

func (v *Validator) ValidateTag() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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