response

package
v0.0.0-...-6f9dc6e Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeSuccess       int = 200
	CodeError         int = 500
	CodeInvalidParams int = 400
	CodeUnauthorized  int = 401
	CodeNotFound      int = 404
	CodeFailAddData   int = 800
)

Variables

View Source
var CodeMsgMap = map[int]string{
	CodeSuccess:       "成功",
	CodeError:         "服务器繁忙,请稍后再试。",
	CodeInvalidParams: "表单验证有误",
	CodeUnauthorized:  "授权失败,请求重新登录。",
	CodeFailAddData:   "添加数据失败",
	CodeNotFound:      "数据不存在",
}

Functions

func Failed

func Failed(w http.ResponseWriter, code int, options ...RespOption)

Failed 错误响应

func FormValidError

func FormValidError(w http.ResponseWriter, msg string)

FormValidError 表单验证错误

func GetMsg

func GetMsg(c int) string

func InternalError

func InternalError(w http.ResponseWriter, options ...RespOption)

InternalError 内部错误

func NotFoundError

func NotFoundError(w http.ResponseWriter)

NotFoundError 页面未找到

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

type Response

type Response struct {
	Page     int         `json:"page,omitempty"`
	PageSize int         `json:"page_size,omitempty"`
	Code     int         `json:"code"`
	Msg      string      `json:"msg"`
	Data     interface{} `json:"data"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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