Documentation ¶
Index ¶
- Constants
- Variables
- func Failed(w http.ResponseWriter, code int, options ...RespOption)
- func FormValidError(w http.ResponseWriter, msg string)
- func GetMsg(c int) string
- func InternalError(w http.ResponseWriter, options ...RespOption)
- func NotFoundError(w http.ResponseWriter)
- func PageSuccess(w http.ResponseWriter, data interface{}, page, pageSize int)
- func SendResponse(w http.ResponseWriter, data interface{}, code int, options ...RespOption)
- func Success(w http.ResponseWriter, data interface{}, options ...RespOption)
- func UnauthorizedError(w http.ResponseWriter, options ...RespOption)
- type RespOption
- func WithAuthHeader(token string) RespOption
- func WithCode(code int) RespOption
- func WithData(data interface{}) RespOption
- func WithHeaders(headers map[string]string) RespOption
- func WithHttpStatusCode(code int) RespOption
- func WithMsg(msg string) RespOption
- func WithPage(page int) RespOption
- func WithPageSize(pageSize int) RespOption
- type Response
Constants ¶
Variables ¶
View Source
var CodeMsgMap = map[int]string{ CodeSuccess: "成功", CodeError: "服务器繁忙,请稍后再试。", CodeInvalidParams: "表单验证有误", CodeUnauthorized: "授权失败,请求重新登录。", CodeFailAddData: "添加数据失败", CodeNotFound: "数据不存在", }
Functions ¶
func InternalError ¶
func InternalError(w http.ResponseWriter, options ...RespOption)
InternalError 内部错误
func PageSuccess ¶
func PageSuccess(w http.ResponseWriter, data interface{}, page, pageSize int)
PageSuccess 分页响应数据
func SendResponse ¶
func SendResponse(w http.ResponseWriter, data interface{}, code int, options ...RespOption)
SendResponse 发送响应
func Success ¶
func Success(w http.ResponseWriter, data interface{}, options ...RespOption)
Success 成功响应
func UnauthorizedError ¶
func UnauthorizedError(w http.ResponseWriter, options ...RespOption)
UnauthorizedError 未授权
Types ¶
type RespOption ¶
type RespOption func(*Response)
func WithAuthHeader ¶
func WithAuthHeader(token string) RespOption
func WithCode ¶
func WithCode(code int) RespOption
func WithData ¶
func WithData(data interface{}) RespOption
func WithHeaders ¶
func WithHeaders(headers map[string]string) RespOption
func WithHttpStatusCode ¶
func WithHttpStatusCode(code int) RespOption
func WithMsg ¶
func WithMsg(msg string) RespOption
func WithPage ¶
func WithPage(page int) RespOption
func WithPageSize ¶
func WithPageSize(pageSize int) RespOption
Click to show internal directories.
Click to hide internal directories.