httputil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGET    = "GET"
	MethodPOST   = "POST"
	MethodPUT    = "PUT"
	MethodDELETE = "DELETE"

	BearerSchema = "Bearer "
)

Common HTTP methods and header values

Variables

This section is empty.

Functions

func CreateHealthChecker

func CreateHealthChecker(db checkers.SQLPinger, disableLog bool) (*health.Health, error)

CreateHealthChecker returns a health checker instance with all checkers registered.

func RespondWithError

func RespondWithError(w http.ResponseWriter, code int, err error)

RespondWithError provides an auxiliary function to handle all failed HTTP requests.

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

RespondWithJSON provides an auxiliary function to return an HTTP response with JSON content and an HTTP status code.

func TransformValidationError

func TransformValidationError(err error) error

TransformValidationError accepts an error from validation and attempts to transform the error message to a more human-readable format.

Types

type ErrResponse

type ErrResponse struct {
	Error string `json:"error"`
}

ErrResponse defines an HTTP error response.

type PaginationQuery

type PaginationQuery struct {
	Order   string
	Reverse bool
	Page    int64
	Limit   int64
}

PaginationQuery defines the structure containing pagination request information from client HTTP requests.

func ParsePaginationQueryParams

func ParsePaginationQueryParams(req *http.Request) (PaginationQuery, error)

ParsePaginationQueryParams parses pagination values from an HTTP request returning an error upon failure.

type PaginationResponse

type PaginationResponse struct {
	Order   string      `json:"order"`
	Reverse bool        `json:"reverse"`
	Page    int64       `json:"page"`
	Limit   int64       `json:"limit"`
	Total   int64       `json:"total"`
	PrevURI string      `json:"prev_uri"`
	NextURI string      `json:"next_uri"`
	Results interface{} `json:"results"`
}

PaginationResponse defines a generic type encapsulating a paginated response. Client should not rely on decoding into this type as the Results is an interface.

func NewPaginationResponse

func NewPaginationResponse(pq PaginationQuery, prev, next, total int64, results interface{}) PaginationResponse

Jump to

Keyboard shortcuts

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