http

package
v0.1.75 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 21 Imported by: 1

README

HTTP server

Environment based configuration

  • ADDR
  • PORT default: 3000
    • Port to be used for listening used if address is not specified
  • ENVIRONMENT default: edge
    • Name of the current environment
  • MAX_HEADER_BYTES default: 1048576 (1 MB)
    • MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body. If zero, DefaultMaxHeaderBytes is used.
  • IDLE_TIMEOUT default: 1h
    • IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled. If IdleTimeout is zero, the value of ReadTimeout is used. If both are zero, ReadHeaderTimeout is used.
    • Everything that can be parsed by ParseDuration
  • READ_TIMEOUT default: 60s
    • ReadHeaderTimeout is the amount of time allowed to read request headers. The connection's read deadline is reset after reading the headers and the Handler can decide what is considered too slow for the body.
    • Everything that can be parsed by ParseDuration
  • WRITE_TIMEOUT default: 60s
    • WriteTimeout is the maximum duration before timing out writes of the response. It is reset whenever a new request's header is read. Like ReadTimeout, it does not let Handlers make decisions on a per-request basis.
    • Everything that can be parsed by ParseDuration

Documentation

Overview

Package http implements the basic pace microservice handlers and a standard microservice server configured via environment variables.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("not found")
	ErrInvalidRequest = errors.New("request is invalid")
)

All exported package errors.

Functions

func ContextTransfer added in v0.1.70

func ContextTransfer(ctx, targetCtx context.Context) context.Context

ContextTransfer copies a request representation from one context to another.

func Environment

func Environment() string

Environment returns the name of the current server environment

func GetUserAgentFromContext added in v0.1.72

func GetUserAgentFromContext(ctx context.Context) (string, error)

GetUserAgentFromContext returns the User-Agent header value from the request that is stored in the context. Returns ErrNotFound if the context does not have a request.

func GetXForwardedForHeaderFromContext added in v0.1.70

func GetXForwardedForHeaderFromContext(ctx context.Context) (string, error)

GetXForwardedForHeaderFromContext returns the X-Forwarded-For header value that would express that you forwarded the request that is stored in the context.

If the remote address of the request is 12.34.56.78:9999 then the value is that remote ip without the port. If the request already includes this header, the remote ip is appended to the value of that header. For example if the request on top of the remote ip also includes the header "X-Forwarded-For: 100.100.100.100" then the resulting value is "100.100.100.100, 12.34.56.78".

Returns ErrNotFound if the context does not have a request. Returns ErrInvalidRequest if the request in the context is malformed, for example because it does not have a remote address, which should never happen.

func JsonApiErrorWriterMiddleware added in v0.1.11

func JsonApiErrorWriterMiddleware(next http.Handler) http.Handler

JsonApiErrorWriterMiddleware is a middleware that wraps http.ResponseWriter such that it forces responses with status codes 4xx/5xx to have Content-Type: application/vnd.api+json

func RequestInContextMiddleware added in v0.1.70

func RequestInContextMiddleware(next http.Handler) http.Handler

RequestInContextMiddleware stores a representation of the request in the context of said request. Some information of that request can then be accessed through the context using functions of this package.

func Router

func Router() *mux.Router

Router returns the default microservice endpoints for health, metrics and debugging

func Server

func Server(handler http.Handler) *http.Server

Server returns a http.Server configured using environment variables, following https://12factor.net/.

Types

This section is empty.

Directories

Path Synopsis
Package jsonapi provides a serializer and deserializer for jsonapi.org spec payloads.
Package jsonapi provides a serializer and deserializer for jsonapi.org spec payloads.
generator
Package generator translates an OpenAPIv3 specification into working go code that handles marshalling, error handling, parameter parsing and validation.
Package generator translates an OpenAPIv3 specification into working go code that handles marshalling, error handling, parameter parsing and validation.
runtime
Package runtime contains functions for marshalling, error handling, parameter parsing and validation.
Package runtime contains functions for marshalling, error handling, parameter parsing and validation.
Package oauth2 provides a middelware that introspects the auth token on behalf of PACE services and populate the request context with useful information when the token is valid, otherwise aborts the request.
Package oauth2 provides a middelware that introspects the auth token on behalf of PACE services and populate the request context with useful information when the token is valid, otherwise aborts the request.

Jump to

Keyboard shortcuts

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