Documentation ¶
Index ¶
- Constants
- Variables
- func ExtractAuthValue(prefix string, str string) (string, error)
- func ExtractBearerAuth(r *http.Request) (token string, err error)
- func ParseJSONBody(r *http.Request, dest interface{}) error
- func WrapHandler(f func()) gin.HandlerFunc
- type DataResponseBadRequest
- type Error
- type Response
- type ResponseBadRequest
- type ResponseHandler
- func (h *ResponseHandler) BadRequest(c *gin.Context, Err *Error) *gin.Context
- func (h *ResponseHandler) CustomizeError(c *gin.Context, Err *Error) *gin.Context
- func (h *ResponseHandler) ErrorHandler(c *gin.Context, err error) *gin.Context
- func (h *ResponseHandler) Forbidden(c *gin.Context, Err *Error) *gin.Context
- func (h *ResponseHandler) InternalErrorResponse(c *gin.Context) *gin.Context
- func (h *ResponseHandler) OK(c *gin.Context) *gin.Context
- func (h *ResponseHandler) Success(c *gin.Context, data interface{}) *gin.Context
- func (h *ResponseHandler) Unauthorized(c *gin.Context, Err *Error) *gin.Context
- type ResponseHandlerOptions
- type ResponseInternalError
- type ResponseSuccess
- type SetOptionFn
Constants ¶
View Source
const ( ContentTypeHeader = "Content-Type" AuthorizationHeader = "Authorization" MetadataKey = "metadata" NotApplicable = "N/A" )
View Source
const ( SubjectContextKey = "subject" NewTokenContextKey = "newToken" )
Context Key
View Source
const ( SuccessCode = "OK" SuccessMessage = "Success" SuccessCodeHTTP = 200 )
View Source
const ( BadRequestCode = "400" BadRequestCodeHTTP = 400 BadRequestMessage = "Bad Request" )
View Source
const ()
View Source
const ( ForbiddenCode = "403" ForbiddenCodeHTTP = 403 ForbiddenMessage = "Forbidden" )
View Source
const ( InternalErrorCode = "500" InternalErrorCodeHTTP = 500 InternalErrorMessage = "Internal Error" )
Variables ¶
View Source
var BadRequestError = NewError("400", "Bad Request", http.StatusBadRequest)
Base Errors
View Source
var EmptyAuthorizationError = NewError("E_AUTH_1", "Authorization value is empty", http.StatusBadRequest)
Authorization Errors
View Source
var ExpiredJWTError = NewError("E_AUTH_5", "Expired JWT", http.StatusUnauthorized)
View Source
var ForbiddenError = NewError("403", "Forbidden", http.StatusForbidden)
View Source
var InternalError = NewError("500", "Internal Error", http.StatusInternalServerError)
View Source
var InvalidJWTFormatError = NewError("E_AUTH_3", "Invalid JWT Format", http.StatusBadRequest)
View Source
var InvalidJWTIssuerError = NewError("E_AUTH_4", "Invalid JWT Issuer", http.StatusUnauthorized)
View Source
var InvalidResourceVersionError = NewError("E_COMM_2", "Invalid Resource Version", http.StatusBadRequest)
View Source
var ListQueryParamError = NewError("E_COMM_2", "Query param cannot be null", http.StatusBadRequest)
View Source
var MalformedTokenError = NewError("E_AUTH_2", "Malformed token", http.StatusBadRequest)
View Source
var ResourceNotFoundError = NewError("E_COMM_1", "Resource Not Found", http.StatusOK)
Common error
View Source
var TooManyRequestError = NewError("429", "Too Many Request", http.StatusTooManyRequests)
Functions ¶
func ParseJSONBody ¶
func WrapHandler ¶
func WrapHandler(f func()) gin.HandlerFunc
Types ¶
type DataResponseBadRequest ¶
type DataResponseBadRequest struct {
Debug map[string]interface{} `json:"__debug"`
}
Data response bad request
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
func NewError ¶
func NewError(code string, message string, httpStatus int, args ...SetOptionFn) *Error
func (*Error) Error ¶
Error implement standard go error interface. If source error is exists then it will print error cause
func (*Error) WithStatus ¶
type Response ¶
type Response struct { Success bool `json:"success" example:"true"` Code string `json:"code" example:"OK"` Message string `json:"message" example:"Success"` Data interface{} `json:"data" swaggerignore:"true"` Header map[string]string `json:"-"` }
Response use standard for response
type ResponseBadRequest ¶
type ResponseHandler ¶
type ResponseHandler struct {
// contains filtered or unexported fields
}
func NewResponseHandler ¶
func NewResponseHandler(args ...ResponseHandlerOptions) ResponseHandler
func (*ResponseHandler) BadRequest ¶
func (*ResponseHandler) CustomizeError ¶
func (*ResponseHandler) ErrorHandler ¶
func (*ResponseHandler) InternalErrorResponse ¶
func (h *ResponseHandler) InternalErrorResponse(c *gin.Context) *gin.Context
func (*ResponseHandler) Success ¶
func (h *ResponseHandler) Success(c *gin.Context, data interface{}) *gin.Context
func (*ResponseHandler) Unauthorized ¶
type ResponseHandlerOptions ¶
type ResponseInternalError ¶
type ResponseSuccess ¶
type SetOptionFn ¶
type SetOptionFn = func(*options)
func SetSuccess ¶
func SetSuccess(success bool) SetOptionFn
Click to show internal directories.
Click to hide internal directories.