Documentation ¶
Index ¶
- Constants
- func JsonBaseResponse(w http.ResponseWriter, v any)
- func JsonBaseResponseCtx(ctx context.Context, w http.ResponseWriter, v any)
- func JsonErrorResponse(w http.ResponseWriter, code int, v any)
- func JsonErrorResponseCtx(ctx context.Context, w http.ResponseWriter, code int, v any)
- type BaseResponse
Constants ¶
View Source
const ( // BusinessMsgOk represents the business message for success. BusinessMsgOk = "common.ok" // BusinessDefaultCodeError represents the business code for error. BusinessDefaultCodeError = "common.unknown" // BusinessContextCodeError represents the business code for ctx error. BusinessContextCodeError = "common.ctx_error" // BusinessCodeInvalidParam represents the business code for invalid param. BusinessCodeInvalidParam = "common.invalid_param" // BusinessCodeUnAuthorized represents the business code for unauthorized. BusinessCodeUnAuthorized = "common.unauthorized" )
Variables ¶
This section is empty.
Functions ¶
func JsonBaseResponse ¶
func JsonBaseResponse(w http.ResponseWriter, v any)
JsonBaseResponse writes v into w with http.StatusOK.
func JsonBaseResponseCtx ¶
func JsonBaseResponseCtx(ctx context.Context, w http.ResponseWriter, v any)
JsonBaseResponseCtx writes v into w with http.StatusOK.
func JsonErrorResponse ¶ added in v0.0.9
func JsonErrorResponse(w http.ResponseWriter, code int, v any)
JsonErrorResponse writes err into w.
func JsonErrorResponseCtx ¶ added in v0.0.9
JsonErrorResponseCtx writes err into w.
Types ¶
type BaseResponse ¶
type BaseResponse[T any] struct { // Code represents the business code, not the http status code. Code string `json:"code"` // Msg represents the business message, if Code = BusinessCodeOK, // and Msg is empty, then the Msg will be set to BusinessMsgOk. Msg string `json:"msg"` // Data represents the business data. Data T `json:"data,omitempty"` }
BaseResponse is the base response struct.
Click to show internal directories.
Click to hide internal directories.