xgin

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	CodeUnknown        = -1
	CodeSuccess        = 0
	CodeBindJsonFailed = 1
	CodePreCheckFailed = 2
)

Variables

This section is empty.

Functions

func DELETE

func DELETE(context *gin.Context, handler func() (interface{}, error))

func Equal added in v1.1.0

func Equal(validate interface{}) func(obj interface{}) bool

func Failed

func Failed(c *gin.Context, err error)

func GET

func GET(context *gin.Context, handler func() (interface{}, error))

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 IsInt added in v1.1.0

func IsInt(obj reflect.Kind) bool

func IsUint added in v1.1.0

func IsUint(obj reflect.Kind) bool

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

func Ok

func Ok(c *gin.Context, data interface{})

func POST

func POST(context *gin.Context, handler func(receive interface{}) (interface{}, error), receive interface{})

func PUT

func PUT(context *gin.Context, handler func(receive interface{}) (interface{}, error), receive interface{})

func Response

func Response(c *gin.Context, result Result)

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 Result struct {
	Code       int64       `json:"code"`
	Data       interface{} `json:"data,omitempty"`
	Message    string      `json:"message,omitempty"`
	Err        error       `json:"-"`
	HttpStatus int         `json:"-"`
}

func NewResult

func NewResult(code int64, data interface{}, err error, status int) Result

type ResultErr

type ResultErr struct {
	Code       int64
	Err        error
	HttpStatus int
}

func CodeErr

func CodeErr(code int64, err error) ResultErr

func DefaultErr

func DefaultErr(err error) ResultErr

func NewResultErr

func NewResultErr(code int64, err error, httpStatus int) ResultErr

func StatusErr

func StatusErr(err error, httpStatus int) ResultErr

func (ResultErr) Error

func (resultErr ResultErr) Error() string

Jump to

Keyboard shortcuts

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