rest

package
v0.0.0-...-3051362 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BadRequestMessage is the default message when the input parameters on a request are wrong or it is malformed.
	BadRequestMessage = "Invalid request parameters."
	// ResourceNotFoundMessage is the default message when a requested resource is not available.
	ResourceNotFoundMessage = "Resource not found."
	// MethodNotAllowedMessage is the default message when a HTTP verb is forbidden on a resource.
	MethodNotAllowedMessage = "Method not allowed on the current resource."
	// InternalServerErrorMessage is the default message when an unexpected condition occurs.
	InternalServerErrorMessage = "Internal Server Error."
	// UnauthorizedMessage is the default message when a request doesn't have the authorization
	UnauthorizedMessage = "Unauthorized"
)

Variables

This section is empty.

Functions

func CreateRouter

func CreateRouter() *gin.Engine

func ErrorWrapper

func ErrorWrapper(handlerFunc WrapperFunc, c *gin.Context)

ErrorWrapper if handlerFunc return a error,then response will be composed from error's information.

func Health

func Health(c *gin.Context)

Health controller for checking service health

func MethodNotAllowedHandler

func MethodNotAllowedHandler(c *gin.Context)

MethodNotAllowedHandler handles requests for registered routes with invalid http methods on their requests

func NoRouteHandler

func NoRouteHandler(c *gin.Context)

NoRouteHandler handles requests for non registered routes

Types

type APIError

type APIError struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
	Err     string `json:"error"`
}

APIError represents the standard error structure for the HTTP responses.

func NewBadRequest

func NewBadRequest(messages ...string) *APIError

NewBadRequest creates an API Error for an invalid or malformed request.

func NewInternalServerError

func NewInternalServerError(messages ...string) *APIError

NewInternalServerError creates an API Error for an unexpected condition.

func NewMethodNotAllowed

func NewMethodNotAllowed(messages ...string) *APIError

NewMethodNotAllowed creates an API Error for a forbidden verb on a resource.

func NewResourceNotFound

func NewResourceNotFound(messages ...string) *APIError

NewResourceNotFound creates an API Error for an unexisting resource.

func NewUnauthorized

func NewUnauthorized(messages ...string) *APIError

type WrapperFunc

type WrapperFunc func(c *gin.Context) *APIError

WrapperFunc is the func type for the custom handlers.

Jump to

Keyboard shortcuts

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