Documentation ¶
Index ¶
- func ErrorJSONHandler(message *ErrorAPIResponse) func(w http.ResponseWriter, r *http.Request)
- func FilterResponseJSONData(data []byte, refFields, fields []string) []byte
- func HandleJSONResponse(w http.ResponseWriter, data Response, refFields []string, filters ...string)
- type Error
- type ErrorAPIResponse
- type HTTPResponse
- type Response
- type SuccessAPIResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorJSONHandler ¶
func ErrorJSONHandler(message *ErrorAPIResponse) func(w http.ResponseWriter, r *http.Request)
ErrorJSONHandler handle error for Gorilla mux router
func FilterResponseJSONData ¶
FilterResponseJSONData filters fields from JSON
func HandleJSONResponse ¶
func HandleJSONResponse(w http.ResponseWriter, data Response, refFields []string, filters ...string)
HandleJSONResponse handle JSON API response
Types ¶
type Error ¶
type Error struct { Message string `json:"message"` Details interface{} `json:"details"` Description string `json:"description"` Code string `json:"code"` }
Error is a generic Application error struct
func FormatAppError ¶ added in v0.0.3
FormatAppError generates a new Error struct from params
type ErrorAPIResponse ¶ added in v0.0.5
type ErrorAPIResponse struct { *Error HTTPResponse *HTTPResponse `json:"http_response"` }
ErrorAPIResponse is an Error response struct
func FormatAPIError ¶ added in v0.0.5
func FormatAPIError(err *Error, httpCode int) *ErrorAPIResponse
FormatAPIError is a helper function to generate error response
func (*ErrorAPIResponse) GetHTTPCode ¶ added in v0.0.5
func (ear *ErrorAPIResponse) GetHTTPCode() int
GetHTTPCode return HTTP code
type HTTPResponse ¶ added in v0.0.5
HTTPResponse is a light HTTP response struct
type Response ¶
type Response interface {
GetHTTPCode() int
}
Response if an interface to get HTTP code
type SuccessAPIResponse ¶ added in v0.0.5
type SuccessAPIResponse struct { Data interface{} `json:"data"` HTTPResponse *HTTPResponse `json:"http_response"` }
SuccessAPIResponse is a Success response struct
func FormatAPISuccess ¶ added in v0.0.5
func FormatAPISuccess(data interface{}, httpCode int) *SuccessAPIResponse
FormatAPISuccess is a helper function to generate success response
func (*SuccessAPIResponse) GetHTTPCode ¶ added in v0.0.5
func (sar *SuccessAPIResponse) GetHTTPCode() int
GetHTTPCode return HTTP code
Click to show internal directories.
Click to hide internal directories.