resp

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BAD_REQUEST_CODE      = -10400
	NONE_LOGIN_CODE       = -10401
	LOGIN_TOKEN_EXPIRED   = -10402
	NO_PERMISSION_CODE    = -10403
	TOO_MANY_REQUEST_CODE = -10429
	INTERNAL_SERVER_CODE  = -10500
	PARAM_FAILD_CODE      = -10600
)

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(ctx *gin.Context, condition bool, msg ...string) bool

BadRequest business-related error returned. Return true means the condition is true

func Custom

func Custom(ctx *gin.Context, bCode int, msg string)

Custom User defined business code and message

func Json

func Json(ctx *gin.Context, data interface{})

Json Normal request with data returned

func LoginExpired

func LoginExpired(ctx *gin.Context, condition bool, msg ...string) bool

LoginExpired Login expired Return true means the condition is true

func NoLogin

func NoLogin(ctx *gin.Context, condition bool, msg ...string) bool

NoLogin Not logged in. Return true means the condition is true

func NoPermission

func NoPermission(ctx *gin.Context, condition bool, msg ...string) bool

NoPermission Insufficient permission error. Return true means the condition is true

func Ok

func Ok(ctx *gin.Context)

Ok Normal request with no data returned

func ParamInvalid

func ParamInvalid(ctx *gin.Context, condition bool, msg ...string) bool

ParamInvalid invalid parameter.

Return true means the condition is true

func ParamValid deprecated

func ParamValid(ctx *gin.Context, err error, obj interface{}) bool

Deprecated: please use ParamValidation. it will be removed in the future

func ParamValidation added in v2.1.4

func ParamValidation(ctx *gin.Context, obj interface{}) bool

ParamValidation parameter validation, return false means that the validation failed

func SeverError

func SeverError(ctx *gin.Context, condition bool, msg ...string) bool

SeverError Server exception Return true means the condition is true

Types

type PaginationResult

type PaginationResult struct {
	Total     int64 `json:"total"`      // Total count
	PageSize  int   `json:"page_size"`  // Page size
	PageIndex int   `json:"page_index"` // Current page index
	Data      any   `json:"data"`       // Response data
}

PaginationResult Paging result

type Resp

type Resp interface {
	// WithMessage set the business message
	WithMessage(message string) Resp
	// WithCode set the business status code
	WithCode(code int) Resp
	// WithData set the response data
	WithData(data interface{}) Resp
	// To response client
	To()
}

type Result

type Result struct {
	Code    int    `json:"err_code"`      // business code
	Message string `json:"err_msg"`       // business message
	Data    any    `json:"ret,omitempty"` // Response data
	// contains filtered or unexported fields
}

Result Return result

func InitResp

func InitResp(ctx *gin.Context, httpCode int) *Result

InitResp initialize a custom structure

func (*Result) To

func (r *Result) To()

func (*Result) WithCode

func (r *Result) WithCode(code int) Resp

func (*Result) WithData

func (r *Result) WithData(data any) Resp

func (*Result) WithMessage

func (r *Result) WithMessage(message string) Resp

Jump to

Keyboard shortcuts

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