Documentation
¶
Index ¶
- Constants
- func BadRequest(w http.ResponseWriter)
- func BadRequestWithReason(w http.ResponseWriter, reason string)
- func Created(w http.ResponseWriter, data interface{})
- func Error(w http.ResponseWriter, reason string, status int)
- func Forbidden(w http.ResponseWriter)
- func InternalError(w http.ResponseWriter)
- func InternalErrorf(w http.ResponseWriter, format string, a ...interface{})
- func NotFound(w http.ResponseWriter)
- func NotFoundWithReason(w http.ResponseWriter, reason string)
- func NotImplemented(w http.ResponseWriter)
- func OK(w http.ResponseWriter, reason string, data interface{})
- func Paginated(w http.ResponseWriter, data interface{}, hasMore bool)
- func Success(w http.ResponseWriter, reason string, data interface{}, status int)
- func Unauthorized(w http.ResponseWriter)
- func UnauthorizedWithReason(w http.ResponseWriter, reason string)
- type PaginatedResponse
- type Response
Constants ¶
const ( // Success reasons ReasonResolved = "resolved" ReasonListed = "listed" ReasonCreated = "created" ReasonUpdated = "updated" ReasonDeleted = "deleted" ReasonIgnored = "ignored" // Error reasons ReasonForbidden = "forbidden" ReasonNotFound = "not_found" ReasonUserNotFound = "user_not_found" ReasonBadRequest = "bad_request" ReasonInternalError = "internal_error" ReasonNotImplemented = "not_implemented" ReasonInvalidToken = "invalid_token" )
Reason codes for API responses
Variables ¶
This section is empty.
Functions ¶
func BadRequestWithReason ¶
func BadRequestWithReason(w http.ResponseWriter, reason string)
BadRequestWithReason writes error with 400 status and custom reason
func Created ¶
func Created(w http.ResponseWriter, data interface{})
Created writes a success response with 201 status
func Error ¶
func Error(w http.ResponseWriter, reason string, status int)
Error writes an error response with the given reason code
func InternalError ¶
func InternalError(w http.ResponseWriter)
InternalError writes error with 500 status
func InternalErrorf ¶
func InternalErrorf(w http.ResponseWriter, format string, a ...interface{})
InternalErrorf writes formatted error with 500 status
func NotFoundWithReason ¶
func NotFoundWithReason(w http.ResponseWriter, reason string)
NotFoundf writes formatted error with 404 status
func NotImplemented ¶
func NotImplemented(w http.ResponseWriter)
NotImplemented writes error with 501 status
func OK ¶
func OK(w http.ResponseWriter, reason string, data interface{})
OK writes a success response with 200 status and custom reason
func Paginated ¶
func Paginated(w http.ResponseWriter, data interface{}, hasMore bool)
Paginated writes a success response with pagination info
func Success ¶
func Success(w http.ResponseWriter, reason string, data interface{}, status int)
Success writes a success response with the given reason code
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter)
Unauthorized writes error with 401 status
func UnauthorizedWithReason ¶
func UnauthorizedWithReason(w http.ResponseWriter, reason string)
UnauthorizedWithReason writes error with 401 status and custom reason
Types ¶
type PaginatedResponse ¶
type PaginatedResponse struct {
Error bool `json:"error"`
Reason string `json:"reason"`
HasMore bool `json:"has_more"`
Data interface{} `json:"data"`
}
PaginatedResponse represents a paginated API response