Documentation
¶
Overview ¶
Validator is a package to provide lots of useful validators to validate API request data.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
func Equal[T comparable](v, target T)
Equal asserts that v must equal to target. Otherwise, it throws an error.
func NotEqual ¶
func NotEqual[T comparable](v, target T)
NotEqual asserts that v must not equal to target. Otherwise, it throws an error.
Types ¶
type Comparable ¶
type Comparable[T any] interface { // Compare compares v with the data. // // - Returns > 0 if the data is greater than v; // - Returns < 0 if it is less than v; // - Returns 0 if it is equal to v. Compare(v T) int }
Comparable represents a data which can be compared with another data.
type Range ¶
type Range[T any] struct { Min, Max Comparable[T] MinInclusive bool // Whether the minimum value is inclusive. MaxInclusive bool // Whether the maximum value is inclusive. }
Range represents a range of values.
func NewRange ¶
func NewRange[T any](min, max Comparable[T]) *Range[T]
NewRange returns a new half-open-interval Range.
type Ranger ¶
Ranger represents a data which can be checked if it is in a range.
func NewEnum ¶
func NewEnum[T comparable](values ...T) Ranger[T]
NewEnum returns a new Ranger which returns true if a value is one of the values.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.