Documentation
¶
Index ¶
- Constants
- func SetCurrentServiceCode(code ServiceCode)
- func SetResponse(c *gin.Context, message string, data interface{}, fails []string, ...)
- func SetResponseWithStatus(c *gin.Context, statusCode int, message string, data interface{}, ...)
- func Wrapper(handler HandlerFunc) func(c *gin.Context)
- func WrapperStatus(handler HttpStatusHandler) func(c *gin.Context)
- type Code
- type CustomCode
- type Handler
- type HandlerFunc
- type HttpStatusHandler
- type MethodCode
- type ModuleCode
- type PageInfo
- type Response
- func StatusAccepted(c *gin.Context) (int, *Response)
- func StatusBadGateway(c *gin.Context) (int, *Response)
- func StatusBadRequest(c *gin.Context) (int, *Response)
- func StatusConflict(c *gin.Context) (int, *Response)
- func StatusCreated(c *gin.Context) (int, *Response)
- func StatusForbidden(c *gin.Context) (int, *Response)
- func StatusGatewayTimeout(c *gin.Context) (int, *Response)
- func StatusInternalServerError(c *gin.Context) (int, *Response)
- func StatusNoContent(c *gin.Context) (int, *Response)
- func StatusNotFound(c *gin.Context) (int, *Response)
- func StatusNotImplemented(c *gin.Context) (int, *Response)
- func StatusOK(c *gin.Context) (int, *Response)
- func StatusServiceUnavailable(c *gin.Context) (int, *Response)
- func StatusUnauthorized(c *gin.Context) (int, *Response)
- func UnknownError(c *gin.Context) (int, *Response)
- type ServiceCode
- type Status
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 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
type CustomCode ¶
type CustomCode string
type Handler ¶ added in v3.0.13
func (*Handler) SetMessage ¶ added in v3.0.13
func (*Handler) SetPageInfo ¶ added in v3.0.13
func (*Handler) SetStatusCode ¶ added in v3.0.13
type HttpStatusHandler ¶ added in v3.0.13
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 (*PageInfo) GetTotalPage ¶ added in v3.0.1
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 StatusGatewayTimeout ¶
StatusGatewayTimeout 504
func StatusNotImplemented ¶
StatusNotImplemented 501
func StatusServiceUnavailable ¶
StatusServiceUnavailable 503
func StatusUnauthorized ¶
StatusUnauthorized 401
type ServiceCode ¶
type ServiceCode string
const ( UserService ServiceCode = "01" ProductService ServiceCode = "02" OrderService ServiceCode = "03" )
Click to show internal directories.
Click to hide internal directories.