handlers

package
v0.0.0-...-b09f343 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: BSD-3-Clause, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Log

func Log(h http.Handler) http.Handler

Log documents incoming requests before passing to child handler

func Recover

func Recover(next http.Handler) http.Handler

Recover catches panics in downstream handlers, sends err to alert client

func Route

func Route(h http.HandlerFunc, isProd bool) http.HandlerFunc

Route composes endpoints by wrapping destination handler with handler pipeline providing tracing with aws x-ray, injecting logging middleware with request details into the context, and error recovery middleware, and gzipping the response

func Static

func Static(reader io.Reader) http.HandlerFunc

Static prepares and returns a http.Handler serving a single file

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler manages the endpoints of the Server

func New

func New(opts ...Opt) (*Handler, error)

New constructs and returns a Handler struct with the specified opts

func (*Handler) Get

func (h *Handler) Get(w http.ResponseWriter, r *http.Request)

Get returns a http endpoint listening for Get quote by attribute requests

func (*Handler) Put

func (h *Handler) Put(w http.ResponseWriter, r *http.Request)

Put reads & validates the given *Quote struct, before saving to DynamoDB

func (*Handler) Random

func (h *Handler) Random(w http.ResponseWriter, r *http.Request)

Random endpoint returns a random quote struct from the dynamodb api

func (*Handler) RouteMap

func (h *Handler) RouteMap(home bool) map[string]http.HandlerFunc

RouteMap returns a map linking endpoint endpoint names to their handler

type Opt

type Opt func(h *Handler) (*Handler, error)

Opt are the configuratio nfunctions used set options on the hander struct

func WithAPI

func WithAPI(a *api.API) Opt

WithAPI sets an API for the handler struct

func WithFS

func WithFS(fs *afs.AFS, static string) Opt

WithFS inserts the given file system client into the server

Jump to

Keyboard shortcuts

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