controller

package
v0.0.0-...-f42576b Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PreviousPaginationQueryParamKey = "previous"
	NextPaginationQueryParamKey     = "next"
	FormDataContentTypeHeaderValue  = "application/x-www-form-urlencoded"
	JSONContentTypeHeaderValue      = "application/json"
	HeaderContentType               = "Content-Type"
	HeaderUnmodifiedSince           = "If-Unmodified-Since"
	HeaderLastModified              = "Last-Modified"
	HeaderRequestID                 = "X-Request-ID"
)

Variables

View Source
var (

	// ErrUnsupportedMediaType is returned when client does not provide appropriate `Content-Type` header
	ErrUnsupportedMediaType = errors.New("media type not supported")
	// ErrConditionalFailed is returned when update is missing `If-Unmodified-Since` header
	ErrConditionalFailed = errors.New("update failed due to mismatch of `If-Unmodified-Since` header value")
	// ErrNotFound is returned when resource is not found
	ErrNotFound = errors.New("request resource not found")
	// ErrBadRequest is returned when protocol for a PUT/POST/DELETE request is not met
	ErrBadRequest = errors.New("bad request: Update is missing `If-Unmodified-Since` header ")
	// ErrBadRequestForRequeue is returned when requeue form param does not match consumer token
	ErrBadRequestForRequeue = errors.New("`requeue` form param must match consumer token")
)
View Source
var NotifyOnInterrupt = func(stop *chan os.Signal) {
	signal.Notify(*stop, os.Interrupt, os.Kill, syscall.SIGTERM)
}

NotifyOnInterrupt registers channel to get notified when interrupt is captured

Functions

func ConfigureAPI

func ConfigureAPI(httpConfig config.HTTPConfig, iListener ServerLifecycleListener, apiRouter *httprouter.Router) *http.Server

ConfigureAPI configures API Server with interrupt handling

func FormatURL

func FormatURL(params []httprouter.Param, urlTemplate string, urlParamNames ...string) (result string)

func GetPagination

func GetPagination(req *http.Request) *data.Pagination
func GetPaginationLinks(req *http.Request, pagination *data.Pagination) map[string]string

func SetupAPIRoutes

func SetupAPIRoutes(apiRouter *httprouter.Router, endpoints ...EndpointController)

func WriteBadRequest

func WriteBadRequest(w http.ResponseWriter)

func WriteErr

func WriteErr(w http.ResponseWriter, err error)

func WriteJSON

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

func WriteNotFound

func WriteNotFound(w http.ResponseWriter)

func WritePreconditionFailed

func WritePreconditionFailed(w http.ResponseWriter)

func WriteStatus

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

func WriteUnsupportedMediaType

func WriteUnsupportedMediaType(w http.ResponseWriter)

Types

type Delete

type Delete interface {
	Delete(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Delete represents DELETE Method Call to a resource

type EndpointController

type EndpointController interface {
	GetPath() string
	FormatAsRelativeLink(params ...httprouter.Param) string
}

EndpointController represents very basic functionality of an endpoint

type Get

type Get interface {
	Get(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Get represents GET Method Call to a resource

type Post

type Post interface {
	Post(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Post represents POST Method Call to a resource

type Put

type Put interface {
	Put(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}

Put represents PUT Method Call to a resource

type ServerLifecycleListener

type ServerLifecycleListener interface {
	StartingServer()
	ServerStartFailed(err error)
	ServerShutdownCompleted()
}

ServerLifecycleListener listens to key server lifecycle error

Jump to

Keyboard shortcuts

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