util

package
v0.0.0-...-606800a Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const TransactionIDKey = "TransactionID"

TransactionIDKey can be used to grab the unique ID from request context

Variables

This section is empty.

Functions

func JSON

func JSON(w io.Writer, data interface{}) error

JSON is a utility function that handlers can use to turn arbitrary structs into JSON and write the response TODO: optionally turn off the marshalIndent to speed up network requests in production

func RequestLogger

func RequestLogger(h http.Handler) http.Handler

RequestLogger complies to the gorilla webkit Middleware interface It is used to log detailed request data and adds a unique transaction ID

Types

type AppRouter

type AppRouter struct {
	*mux.Router
}

func (*AppRouter) AppHandler

func (a *AppRouter) AppHandler(path string, f func(w http.ResponseWriter, r *http.Request) error) *mux.Route

type Handler

type Handler struct {
	H func(w http.ResponseWriter, r *http.Request) error
}

Handler struct allows for functions to return errors and still implement the the http.Handler interface

func (Handler) ServeHTTP

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

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

type StatusError

type StatusError struct {
	Message string
	Code    int
	// contains filtered or unexported fields
}

StatusError is handy for when you want to return something other than 500 internal server error

func (*StatusError) Error

func (e *StatusError) Error() string

func (*StatusError) Status

func (e *StatusError) Status() int

Status returns the http response code

Jump to

Keyboard shortcuts

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