check

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker struct {
	SolveError func(err error)
}

func (*Checker) Assert added in v1.3.1

func (checker *Checker) Assert(condition bool, errMsg string)

func (*Checker) AssertError added in v1.3.2

func (checker *Checker) AssertError(err error)

func (*Checker) Check added in v1.3.1

func (checker *Checker) Check(name string, data any) *Context

type Context added in v1.3.1

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

func (*Context) Assert added in v1.3.1

func (ctx *Context) Assert(condition bool, errMsg string) *Context

func (*Context) AssertError added in v1.3.2

func (ctx *Context) AssertError(err error) *Context

func (*Context) Eq added in v1.3.1

func (ctx *Context) Eq(expect any) *Context

check whether value == expect

Only valid for int/int8/.../uint/uint8/.../float32/float64/string and their pointer.

It will also be invalid if the types do not match. For example:

If value is int and expect is string, it is invalid;
If value is int and expect is float32, it is valid.

func (*Context) Error added in v1.3.1

func (ctx *Context) Error() error

func (*Context) Ge added in v1.3.1

func (ctx *Context) Ge(expect any) *Context

Check whether value >= expect. The type handling mechanism is the same as `Eq`.

func (*Context) Gt added in v1.3.1

func (ctx *Context) Gt(expect any) *Context

Check whether value > expect. The type handling mechanism is the same as `Eq`.

func (*Context) In added in v1.3.1

func (ctx *Context) In(expect ...any) *Context

Check whether value is in expect.

When compare value with items in expect, it is only valid for int/int8/.../uint/uint8/.../float32/float64/string and their pointer.

func (*Context) IsEmail added in v1.3.1

func (ctx *Context) IsEmail() *Context

check whether value is a valid email

func (*Context) IsNumeric added in v1.3.1

func (ctx *Context) IsNumeric() *Context

check whether value consists of 0-9

func (*Context) IsURL added in v1.3.1

func (ctx *Context) IsURL() *Context

check whether value is a valid URL

func (*Context) Le added in v1.3.1

func (ctx *Context) Le(expect any) *Context

Check whether value <= expect. The type handling mechanism is the same as `Eq`.

func (*Context) Length added in v1.3.1

func (ctx *Context) Length(min, max int) *Context

check whether min <= utf8.RuneCountInString(value) <= max

func (*Context) Lt added in v1.3.1

func (ctx *Context) Lt(expect any) *Context

Check whether value < expect. The type handling mechanism is the same as `Eq`.

func (*Context) Match added in v1.3.1

func (ctx *Context) Match(expect string) *Context

Check whether value matches expect (expect is a regexp)

Only valid when value is string/*string

func (*Context) Neq added in v1.3.1

func (ctx *Context) Neq(expect any) *Context

Check whether value != expect. The type handling mechanism is the same as `Eq`.

func (*Context) NotBlank added in v1.3.1

func (ctx *Context) NotBlank() *Context

func (*Context) NotEmpty added in v1.3.1

func (ctx *Context) NotEmpty() *Context

func (*Context) NotIn added in v1.3.1

func (ctx *Context) NotIn(expect ...any) *Context

Check whether value is not in expect. The type handling mechanism is the same as `In`.

func (*Context) NotNil added in v1.3.1

func (ctx *Context) NotNil() *Context

func (*Context) Range added in v1.3.1

func (ctx *Context) Range(min, max float64) *Context

check whether min <= value <= max

Only valid for int/int8/.../uint/uint8/.../float32/float64 or pointer to them.

func (*Context) Size added in v1.3.1

func (ctx *Context) Size(min, max int) *Context

check whether min <= len(value) <= max (value can be string, slice, array, or map)

For string, what is checked is the number of bytes. If you want to check the number of characters(rune), use `Length`.

Jump to

Keyboard shortcuts

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