Documentation
¶
Index ¶
- Constants
- func DELETE(context *gin.Context, handler func() (interface{}, error))
- func Equal(validate interface{}) func(obj interface{}) bool
- func Failed(c *gin.Context, err error)
- func GET(context *gin.Context, handler func() (interface{}, error))
- func Greater(validate interface{}) func(obj interface{}) bool
- func GreaterEqual(validate interface{}) func(obj interface{}) bool
- func IsInt(obj reflect.Kind) bool
- func IsUint(obj reflect.Kind) bool
- func Less(validate interface{}) func(obj interface{}) bool
- func LessEqual(validate interface{}) func(obj interface{}) bool
- func Ok(c *gin.Context, data interface{})
- func POST(context *gin.Context, handler func(receive interface{}) (interface{}, error), ...)
- func PUT(context *gin.Context, handler func(receive interface{}) (interface{}, error), ...)
- func Response(c *gin.Context, result Result)
- type IPreCheck
- type ParamError
- type Result
- type ResultErr
Examples ¶
Constants ¶
View Source
const ( CodeUnknown = -1 CodeSuccess = 0 CodeBindJsonFailed = 1 CodePreCheckFailed = 2 )
Variables ¶
This section is empty.
Functions ¶
func Greater ¶ added in v1.1.0
func Greater(validate interface{}) func(obj interface{}) bool
Greater only support int/uint type, otherwise return true
func GreaterEqual ¶ added in v1.1.0
func GreaterEqual(validate interface{}) func(obj interface{}) bool
GreaterEqual only support int/uint type, otherwise return true
func Less ¶ added in v1.1.0
func Less(validate interface{}) func(obj interface{}) bool
Less only support int/uint type, otherwise return true
func LessEqual ¶ added in v1.1.0
func LessEqual(validate interface{}) func(obj interface{}) bool
LessEqual only support int/uint type, otherwise return true
Types ¶
type IPreCheck ¶
type IPreCheck interface {
PreCheck() *ParamError
}
type ParamError ¶
type ParamError struct {
IllegalParams []string
}
func NewParamError ¶
func NewParamError() *ParamError
func Validate ¶ added in v1.1.0
func Validate(paramName string, param interface{}, validateFunc func(obj interface{}) bool) *ParamError
Validate example: Validate("param", 20, Less(30)) -> true; Validate("param", 20, Greater(30)) -> false; Validate("param", 20, Equal(20)) -> true
Example ¶
fmt.Println(Validate("", 2, Less(3)))
fmt.Println(Validate("", 2, Less(1)))
fmt.Println(Validate("", 2, LessEqual(2)))
fmt.Println(Validate("", 2, LessEqual(3)))
fmt.Println(Validate("", 2, LessEqual(1)))
fmt.Println(Validate("", 2, Equal(2)))
fmt.Println(Validate("", 2, Equal(3)))
fmt.Println(Validate("", 2, Greater(1)))
fmt.Println(Validate("", 2, Greater(3)))
fmt.Println(Validate("", 2, GreaterEqual(2)))
fmt.Println(Validate("", 2, GreaterEqual(1)))
fmt.Println(Validate("", 2, GreaterEqual(3)))
Output: true false true true false true false true false true true false
func (ParamError) Error ¶
func (err ParamError) Error() string
func (*ParamError) Validate ¶ added in v1.1.0
func (err *ParamError) Validate(paramName string, param interface{}, validateFunc func(obj interface{}) bool)
Validate example: Validate("param", 20, Less(30)) -> true; Validate("param", 20, Greater(30)) -> false; Validate("param", 20, Equal(20)) -> true
type Result ¶
type ResultErr ¶
func DefaultErr ¶
Click to show internal directories.
Click to hide internal directories.