gresponse

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MulanPSL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INVALID              = -1
	DB_SAVE_ERROR        = -2
	DB_READ_ERROR        = -3
	CACHE_SAVE_ERROR     = -4
	CACHE_READ_ERROR     = -5
	FILE_SAVE_ERROR      = -6
	LOGIN_ERROR          = -7
	NOT_EXISTS           = -8
	JSON_PARSE_FAIL      = -9
	TYPE_ERROR           = -10
	NUMBER_MATCH_ERROR   = -11
	EMPTY_PARAMS         = -12
	DATA_EXISTS          = -13
	AUTH_ERROR           = -14
	OTHER_LOGIN          = -16
	VERSION_INVALID      = -17
	CURL_ERROR           = -18
	RECORD_NOT_FOUND     = -19  // 记录未找到
	DELETE_FAILED        = -20  // 删除失败
	ADD_FAILED           = -21  // 添加记录失败
	UPDATE_FAILED        = -22  // 添加记录失败
	PARAM_INVALID        = -995 // 参数无效
	ACCESS_TOKEN_TIMEOUT = -996
	SESSION_TIMEOUT      = -997
	UNKNOWN              = -998
	EXCEPTION            = -999
)
View Source
const (
	Buniss_Other   int = 0 //0其它
	Buniss_Add     int = 1 //1新增
	Buniss_Edit    int = 2 //2修改
	Buniss_Del     int = 3 //3删除
	Buniss_Auth    int = 4 //4授权
	Buniss_Export  int = 5 //5导出
	Buniss_Import  int = 6 //6导入
	Buniss_Retreat int = 7 //7强退
	Buniss_Clean   int = 8 //8清空数据
)
View Source
const (
	Status202 int = 202 //(已接受)服务器已接受请求,但尚未处理
	Status204 int = 204 //(无内容)服务器成功处理了请求,但没有返回任何内容
	Status206 int = 206 //(部分内容)服务器成功处理了部分 GET 请求

	Status401 int = 401 //(未授权)请求要求身份验证。对于登录后请求的网页,服务器可能返回此响应
	Status403 int = 403 //(禁止)服务器拒绝请求
	Status412 int = 412 //前提条件失败
	Status417 int = 417 //执行失败
	Status500 int = 500 //(服务器内部错误)服务器遇到错误,无法完成请求
)
View Source
const (
	SUCCESS      = 0
	ERROR        = 1
	NOTLOGIN     = 2
	UNAUTHORIZED = 3
)

Variables

This section is empty.

Functions

func CodeMsg

func CodeMsg(code int) string

func ErrorCheck

func ErrorCheck(r *ghttp.Request, err error)

错误检测

func Fail

func Fail(r *ghttp.Request)

func FailWithData

func FailWithData(r *ghttp.Request, data interface{})

func FailWithDetailed

func FailWithDetailed(r *ghttp.Request, code int, data interface{}, message string)

func FailWithMessage

func FailWithMessage(r *ghttp.Request, message string)

func GetTranslate

func GetTranslate(r *ghttp.Request, msg string, sl, tl string) (message string)

func Json

func Json(r *ghttp.Request, code int, message string, data ...interface{})

标准返回结果数据结构封装。

func JsonExit

func JsonExit(r *ghttp.Request, err int, msg string, data ...interface{})

返回JSON数据并退出当前HTTP执行函数。

func NullCheck

func NullCheck(r *ghttp.Request, data ...interface{})

检测是否空值

func Ok

func Ok(r *ghttp.Request)

func OkDetailed

func OkDetailed(r *ghttp.Request, data interface{}, message string)

func OkWithData

func OkWithData(r *ghttp.Request, data interface{})

func OkWithMessage

func OkWithMessage(r *ghttp.Request, message string)

func Result

func Result(r *ghttp.Request, code int, data interface{}, message string)

func RoundRobin

func RoundRobin(mps map[string]string, index int) (AppId, Sign string)

func SetAdapter

func SetAdapter(redis gcache.Adapter)

func Translate

func Translate(r *ghttp.Request, message string) (string, error)

func TranslateCtx

func TranslateCtx(ctx context.Context, message string) (string, error)

func WithStatus

func WithStatus(r *ghttp.Request, status int, code int, data interface{}, message string)

带上状态码的信息

Types

type BaiduTranslateRsp

type BaiduTranslateRsp struct {
	ErrorCode string `json:"error_code"`
	ErrorMsg  string `json:"error_msg"`

	From        string `json:"from"`
	To          string `json:"to"`
	TransResult []struct {
		Src string `json:"src"`
		Dst string `json:"dst"`
	} `json:"trans_result"`
}

type JsonResponse

type JsonResponse struct {
	Code    int         `json:"code"` // 错误码((0:成功, 1:失败, >1:错误码))
	Data    interface{} `json:"data"` // 返回数据(业务接口定义具体数据结构)
	Message string      `json:"msg"`  // 提示信息
}

数据返回通用JSON数据结构

func FailRes

func FailRes(msg string) JsonResponse

失败

func SuccRes

func SuccRes(data interface{}) JsonResponse

成功

func Unauthorized

func Unauthorized(msg string, data interface{}) JsonResponse

认证失败

func (JsonResponse) DataString

func (resp JsonResponse) DataString() string

获取Data转字符串

func (JsonResponse) Get

func (resp JsonResponse) Get(key string) interface{}

获取Data值

func (JsonResponse) GetInt

func (resp JsonResponse) GetInt(key string) int

获取Data值转Int

func (JsonResponse) GetString

func (resp JsonResponse) GetString(key string) string

获取Data值转字符串

func (JsonResponse) Json

func (resp JsonResponse) Json() string

func (JsonResponse) Success

func (resp JsonResponse) Success() bool

type Limiters

type Limiters struct {
	TencentLimit *glimiter.Period //单个接口限流
}

Jump to

Keyboard shortcuts

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