Documentation ¶
Index ¶
- Constants
- Variables
- func FastRespJsonConfigOn() (err error)
- func GetCtxVar(ctx context.Context, key any, def ...any) *gvar.Var
- func SetCtxVar(ctx context.Context, key, value any) context.Context
- func VerifyDataToJson(r *ghttp.Request, i VerifyHandlerInterface) *gjson.Json
- func VerifyDataToStruct[T VerifyHandlerInterface](r *ghttp.Request, i T) T
- func VerifyHandler(r *ghttp.Request, i VerifyHandlerInterface)
- type FastResponse
- func (t *FastResponse) Callback(fn func(t *FastResponse)) *FastResponse
- func (t *FastResponse) ErrorStatus() *FastResponse
- func (t *FastResponse) GetRequest() *ghttp.Request
- func (t *FastResponse) Resp(args ...any)
- func (t *FastResponse) Response(args ...any)
- func (t *FastResponse) SetData(data any) *FastResponse
- func (t *FastResponse) SetMsg(msg string) *FastResponse
- func (t *FastResponse) SetRespMode(mode uint8) *FastResponse
- func (t *FastResponse) SetStatus(status int) *FastResponse
- func (t *FastResponse) SetStatusCode(statusCode int) *FastResponse
- func (t *FastResponse) SuccessStatus() *FastResponse
- func (t *FastResponse) TxRollBack(tx gdb.TX) *FastResponse
- type FastResponseOptionType
- type VerifyHandlerInterface
Constants ¶
View Source
const ( JsonRespMode uint8 = iota MsgRespMode )
Variables ¶
View Source
var FastResponseOption = &FastResponseOptionType{
DefaultSuccessCode: 1000,
DefaultErrorCode: 1001,
DefaultSuccessStatusCode: 200,
DefaultErrorStatusCode: 500,
MsgName: "msg",
CodeName: "code",
DataName: "data",
TimeName: "time",
SuccessMsg: "SUCCESS !!!",
ErrorMsg: "ERROR !!!",
}
FastResponseOption 快速返回设置
View Source
var GetMessageToStatus func(status int) string = nil
GetMessageToStatus 根据状态获取 Message
View Source
var RespAdvancedOption func(t *FastResponse, m *map[string]any) = nil
RespAdvancedOption 高级配置
View Source
var RespErrorMsg = false
RespErrorMsg 当获取到Error时返回错误信息
View Source
var VerifyDefaultErrMsgResp = func(r *ghttp.Request, err gvalid.Error) { FastResp(r).SetStatus(1001).Resp(err.FirstError().Error()) }
VerifyDefaultErrMsgResp msg 默认处理方式
View Source
var VerifyDefaultMsgNilResp = func(r *ghttp.Request) { FastResp(r).SetStatus(1001).Resp("参数错误") }
VerifyDefaultMsgNilResp 空 msg 默认处理方式
Functions ¶
func FastRespJsonConfigOn ¶
func FastRespJsonConfigOn() (err error)
FastRespJsonConfigOn 快速返回 json 配置开启
func VerifyDataToJson ¶
func VerifyDataToJson(r *ghttp.Request, i VerifyHandlerInterface) *gjson.Json
func VerifyDataToStruct ¶
func VerifyDataToStruct[T VerifyHandlerInterface](r *ghttp.Request, i T) T
func VerifyHandler ¶
func VerifyHandler(r *ghttp.Request, i VerifyHandlerInterface)
Types ¶
type FastResponse ¶
type FastResponse struct { Status int StatusCode int Msg string Data any Err error IfMode bool // contains filtered or unexported fields }
FastResponse 快速返回
func CreateFastResponse ¶
func CreateFastResponse(r *ghttp.Request, args ...any) *FastResponse
CreateFastResponse 创建快速返回
func (*FastResponse) Callback ¶
func (t *FastResponse) Callback(fn func(t *FastResponse)) *FastResponse
Callback 当条件为 true 时触发
func (*FastResponse) ErrorStatus ¶
func (t *FastResponse) ErrorStatus() *FastResponse
ErrorStatus 错误状态
func (*FastResponse) GetRequest ¶
func (t *FastResponse) GetRequest() *ghttp.Request
func (*FastResponse) Resp ¶
func (t *FastResponse) Resp(args ...any)
func (*FastResponse) Response ¶
func (t *FastResponse) Response(args ...any)
Response 执行返回操作 (old) Msg 参数 1 要返回的文本参数 Data 参数 2 要返回的数据 Status 要返回的 code 码
func (*FastResponse) SetData ¶
func (t *FastResponse) SetData(data any) *FastResponse
SetData 设置返回数据
func (*FastResponse) SetRespMode ¶
func (t *FastResponse) SetRespMode(mode uint8) *FastResponse
func (*FastResponse) SetStatus ¶
func (t *FastResponse) SetStatus(status int) *FastResponse
SetStatus 设置状态
func (*FastResponse) SetStatusCode ¶
func (t *FastResponse) SetStatusCode(statusCode int) *FastResponse
SetStatusCode 设置返回的 HTTP 状态码
func (*FastResponse) SuccessStatus ¶
func (t *FastResponse) SuccessStatus() *FastResponse
SuccessStatus 成功状态
func (*FastResponse) TxRollBack ¶
func (t *FastResponse) TxRollBack(tx gdb.TX) *FastResponse
TxRollBack 事务推回
type FastResponseOptionType ¶
type FastResponseOptionType struct { // 返回 code DefaultSuccessCode int `json:"defaultSuccessCode"` DefaultErrorCode int `json:"defaultErrorCode"` // http code DefaultSuccessStatusCode int `json:"defaultSuccessStatusCode"` DefaultErrorStatusCode int `json:"defaultErrorStatusCode"` // 返回字段 MsgName string `json:"msgName"` CodeName string `json:"codeName"` DataName string `json:"dataName"` TimeName string `json:"timeName"` // 返回 message SuccessMsg string `json:"successMsg"` ErrorMsg string `json:"errorMsg"` }
FastResponseOptionType 快速返回设置类型
Click to show internal directories.
Click to hide internal directories.