response

package
v3.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Get    MethodCode = "0"
	Post              = "1"
	Put               = "2"
	Patch             = "3"
	Delete            = "4"
)
View Source
const (
	CodeStatus = "codeStatus"
	ModuleName = "moduleName"
	MethodName = "methodName"
)

code 專用

View Source
const (
	DataKey = "responseData"
)

data

View Source
const (
	FailKey = "responseFails"
)

fail

View Source
const (
	MessageKey = "responseMessage"
)

message

View Source
const (
	PageKey = "pageInfo"
)

pageInfo

View Source
const (
	StatusCodeKey = "statusCodeKey"
)

Variables

This section is empty.

Functions

func SetCurrentServiceCode

func SetCurrentServiceCode(code ServiceCode)

func SetResponse added in v3.0.1

func SetResponse(c *gin.Context, message string, data interface{}, fails []string, pageInfo *PageInfo)

SetResponse 設定 response 相關資料進入 gin 的 context

func SetResponseWithStatus added in v3.0.13

func SetResponseWithStatus(c *gin.Context, statusCode int, message string, data interface{}, fails []string, pageInfo *PageInfo)

func Wrapper

func Wrapper(handler HandlerFunc) func(c *gin.Context)

Wrapper 在 register routing 時加入錯誤 handler

func WrapperStatus added in v3.0.13

func WrapperStatus(handler HttpStatusHandler) func(c *gin.Context)

WrapperStatus 在 register routing 時加入錯誤 handler

Types

type Code

type Code int

func GetCode

func GetCode(status Status, service ServiceCode, module ModuleCode, method MethodCode, customCode ...string) Code

func NewCode

func NewCode(c *gin.Context) Code

type CustomCode

type CustomCode string

type Handler added in v3.0.13

type Handler struct {
	*gin.Context
}

func New added in v3.0.13

func New(ctx *gin.Context) *Handler

func (*Handler) AddFails added in v3.0.13

func (h *Handler) AddFails(msg ...string) *Handler

func (*Handler) SetData added in v3.0.13

func (h *Handler) SetData(data interface{}) *Handler

func (*Handler) SetMessage added in v3.0.13

func (h *Handler) SetMessage(msg string) *Handler

func (*Handler) SetPageInfo added in v3.0.13

func (h *Handler) SetPageInfo(info *PageInfo) *Handler

func (*Handler) SetStatusCode added in v3.0.13

func (h *Handler) SetStatusCode(code int) *Handler

type HandlerFunc

type HandlerFunc func(c *gin.Context) error

HandlerFunc 錯誤 handler

type HttpStatusHandler added in v3.0.13

type HttpStatusHandler func(c *gin.Context)

HttpStatusHandler 依照 http status code 判斷要回傳什麼

type MethodCode

type MethodCode string

func GetMethodCode

func GetMethodCode(in string) MethodCode

type ModuleCode

type ModuleCode string

type PageInfo

type PageInfo struct {
	Count       int `json:"count"`       //全部資料數量
	Limit       int `json:"limit"`       //限制搜尋筆數
	TotalPage   int `json:"totalPage"`   //總共頁數
	CurrentPage int `json:"currentPage"` //目前所在頁數
}

func NewPageInfo added in v3.0.3

func NewPageInfo(count int) *PageInfo

func (*PageInfo) GetTotalPage added in v3.0.1

func (p *PageInfo) GetTotalPage() *PageInfo

func (*PageInfo) Setup added in v3.0.3

func (p *PageInfo) Setup(c *gin.Context) *PageInfo

type Response

type Response struct {
	Code     Code        `json:"code"`               //系統定義代碼
	Message  string      `json:"message"`            //訊息
	Data     interface{} `json:"data"`               //回傳資料
	PageInfo *PageInfo   `json:"pageInfo,omitempty"` //分頁資訊
	Fails    []string    `json:"fails,omitempty"`    //錯誤訊息
}

func StatusAccepted

func StatusAccepted(c *gin.Context) (int, *Response)

StatusAccepted 允許存取

func StatusBadGateway

func StatusBadGateway(c *gin.Context) (int, *Response)

StatusBadGateway 502

func StatusBadRequest

func StatusBadRequest(c *gin.Context) (int, *Response)
400 系列

StatusBadRequest 400

func StatusConflict

func StatusConflict(c *gin.Context) (int, *Response)

StatusConflict 409

func StatusCreated

func StatusCreated(c *gin.Context) (int, *Response)

StatusCreated 建立成功

func StatusForbidden

func StatusForbidden(c *gin.Context) (int, *Response)

StatusForbidden 403

func StatusGatewayTimeout

func StatusGatewayTimeout(c *gin.Context) (int, *Response)

StatusGatewayTimeout 504

func StatusInternalServerError

func StatusInternalServerError(c *gin.Context) (int, *Response)
500 系列

ServerError 500 伺服器錯誤

func StatusNoContent

func StatusNoContent(c *gin.Context) (int, *Response)

StatusNoContent 沒有資料

func StatusNotFound

func StatusNotFound(c *gin.Context) (int, *Response)

NotFoundError 404 錯誤

func StatusNotImplemented

func StatusNotImplemented(c *gin.Context) (int, *Response)

StatusNotImplemented 501

func StatusOK

func StatusOK(c *gin.Context) (int, *Response)

StatusOK 運行成功

func StatusServiceUnavailable

func StatusServiceUnavailable(c *gin.Context) (int, *Response)

StatusServiceUnavailable 503

func StatusUnauthorized

func StatusUnauthorized(c *gin.Context) (int, *Response)

StatusUnauthorized 401

func UnknownError

func UnknownError(c *gin.Context) (int, *Response)

UnknownError 未知錯誤,回傳 500

func (*Response) Error

func (r *Response) Error() string

type ServiceCode

type ServiceCode string
const (
	UserService    ServiceCode = "01"
	ProductService ServiceCode = "02"
	OrderService   ServiceCode = "03"
)

type Status

type Status string
const (
	Failed  Status = "1"
	Success        = "2"
)

Jump to

Keyboard shortcuts

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