http

package
v0.48.5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 14 Imported by: 26

Documentation

Overview

Package http implements a core suite of HTTP functions for use inside Moov. These packages are designed to be used in production to provide insight without an excessive performance tradeoff.

This package implements several opininated response functions (See Problem, InternalError) and stateless CORS handling under our load balancing setup. They may not work for you.

This package also implements a wrapper around http.ResponseWriter to log X-Request-ID, timing and the resulting status code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCORSHandler

func AddCORSHandler(r *mux.Router)

AddCORSHandler captures Corss Origin Resource Sharing (CORS) requests by looking at all OPTIONS requests for the Origin header, parsing that and responding back with the other Access-Control-Allow-* headers.

Docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

func GetRequestID added in v0.10.0

func GetRequestID(r *http.Request) string

GetRequestID returns the Moov header value for request IDs

func GetSkipAndCount added in v0.11.1

func GetSkipAndCount(r *http.Request) (skip int, count int, exists bool, err error)

GetSkipAndCount returns the skip and count pagination values from the query parameters - skip is the number of records to pass over before starting a search (max math.MaxInt32) - count is the number of records to retrieve in the search (max 10,000) - exists indicates if skip or count was passed into the request URL

func GetUserID added in v0.10.0

func GetUserID(r *http.Request) string

GetUserID returns the Moov userId from HTTP headers

func InternalError

func InternalError(w http.ResponseWriter, err error) string

InternalError writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.

Returned is the calling file and line number: server.go:33

func LimitedSkipCount added in v0.39.0

func LimitedSkipCount(r *http.Request, skipLimit, countLimit int) (skip int, count int, exists bool, err error)

LimitedSkipCount returns the skip and count pagination values from the request's query parameters See GetSkipAndCount for descriptions of each parameter

func Problem

func Problem(w http.ResponseWriter, err error)

Problem writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.

func SetAccessControlAllowHeaders

func SetAccessControlAllowHeaders(w http.ResponseWriter, origin string)

SetAccessControlAllowHeaders writes Access-Control-Allow-* headers to a response to allow for further CORS-allowed requests.

Types

type Direction added in v0.47.0

type Direction string
const (
	Ascending  Direction = "ASC"
	Descending Direction = "DESC"
)

type OrderBy added in v0.47.0

type OrderBy struct {
	Name      string
	Direction Direction
}

func GetOrderBy added in v0.47.0

func GetOrderBy(r *http.Request) ([]OrderBy, error)

GetOrderBy returns the field names and direction to order the response by

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter implements Go's standard library http.ResponseWriter to complete HTTP requests

func Wrap

Wrap returns a ResponseWriter usable by applications. No parts of the Request are inspected or ResponseWriter modified.

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(code int)

WriteHeader sends an HTTP response header with the provided status code, records response duration, and optionally records the HTTP metadata in a go-kit log.Logger

Directories

Path Synopsis
Package bind returns well known HTTP local bind addresses for Moov services.
Package bind returns well known HTTP local bind addresses for Moov services.

Jump to

Keyboard shortcuts

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