apiutil

package
v0.0.0-...-099c1f4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2019 License: AGPL-3.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const DEFAULT_PAGE_SIZE = 100

Variables

This section is empty.

Functions

func EmptyOkHandler

func EmptyOkHandler(w http.ResponseWriter, r *http.Request)

EmptyOkHandler is an empty 200 response, often used for OPTIONS requests that responds with headers set in addCorsHeaders

func HealthCheckHandler

func HealthCheckHandler(w http.ResponseWriter, r *http.Request)

HealthCheckHandler is a basic "hey I'm fine" for load balancers & co TODO - add Database connection & proper configuration checks here for more accurate health reporting

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, r *http.Request)

func ReqParamBool

func ReqParamBool(key string, r *http.Request) (bool, error)

TODO - consider providing a default param & removing the error

func ReqParamInt

func ReqParamInt(key string, r *http.Request) (int, error)

TODO - consider providing a default param & removing the error

func WriteErrResponse

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

func WriteMessageResponse

func WriteMessageResponse(w http.ResponseWriter, message string, data interface{}) error

func WritePageResponse

func WritePageResponse(w http.ResponseWriter, data interface{}, r *http.Request, p Page) error

func WriteResponse

func WriteResponse(w http.ResponseWriter, data interface{}) error

Types

type Page

type Page struct {
	Number int `json:"page"`
	Size   int `json:"pageSize"`
}

a page represents pagination data & common pagination

func NewPage

func NewPage(number, size int) Page

func NewPageFromOffsetAndLimit

func NewPageFromOffsetAndLimit(offset, limit int) Page

NewPageFromOffsetAndLimit converts a offset and Limit to a Page struct

func PageFromRequest

func PageFromRequest(r *http.Request) Page

pull pagination params from an http request

func (Page) Limit

func (p Page) Limit() int

func (Page) Offset

func (p Page) Offset() int

Jump to

Keyboard shortcuts

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