httputil

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// code= 100x... 用户模块的错误
	ERROR_USERNAME_USED        = 1001
	ERROR_PASSWORD_WRONG       = 1002
	ERROR_ABNORMAL_PERMISSIONS = 1003

	// code= 200x... token 相关错误
	ERROR_TOKEN_NOT_EXIST = 2001
	ERROR_TOKEN_WRONG     = 2002
	ERROR_TOKEN_EXPIRE    = 2003

	// code= 300x... 参数验证错误
	ERROR_PARAMETER_VALIDATION = 3001
)
View Source
const (
	ERROR   = 500
	SUCCESS = 200
)

Variables

This section is empty.

Functions

func Fail

func Fail(c *gin.Context)

func FailWithError

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

统一异常处理

func Ok

func Ok(c *gin.Context)

func OkWithData

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

func ValidateBind added in v1.0.4

func ValidateBind(c *gin.Context, param interface{}) bool

bind请求体并进行参数验证

Types

type BusinessError

type BusinessError struct {
	Code int
}

func (BusinessError) Error

func (e BusinessError) Error() string

type HTTPError

type HTTPError struct {
	Code int    `json:"code" example:"500"`
	Msg  string `json:"msg" example:"操作失败"`
}

HTTPError example

type Meta

type Meta struct {
	Msg  string `json:"msg" example:"操作成功"`
	Code int    `json:"code" example:"200"`
}

type Response

type Response struct {
	Data interface{} `json:"data"`
	Meta
}

Jump to

Keyboard shortcuts

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