httputil

package module
v0.0.0-...-517cbbe Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: MIT Imports: 8 Imported by: 0

README

httputil

A bunch of utilities I often use while writing servers and APIs in go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSlashForRoot

func AddSlashForRoot(next http.Handler) http.Handler

AddSlashForRoot adds a slash if the path is the root path. This is necessary for our subrouters where there may be a root.

func AllowedHeaders

func AllowedHeaders() handlers.CORSOption

AllowedHeaders returns a standard AllowedHeaders handlers.CORSOption.

func AllowedMethods

func AllowedMethods() handlers.CORSOption

AllowedMethods returns a handlers.CORSOption allowing all standard rest methods.

func AllowedOrigins

func AllowedOrigins() handlers.CORSOption

AllowedOrigins returns a handlers.CORSOption allowing all origins.

func CORS

func CORS(h http.Handler) http.Handler

CORS wraps a http.Handler with the `handlers.CORSOption`s.

func GetInt

func GetInt(v url.Values, key string, defaultValue int) int

GetInt returns an integer value from a URL query.

func JsonEncode

func JsonEncode(w http.ResponseWriter, v interface{}) error

JsonEncode marshals an interface and writes it to the response.

func JsonError

func JsonError(w http.ResponseWriter, responseCode int, msg string)

JsonError writes an Error to the ResponseWriter with the provided information.

func JsonSuccess

func JsonSuccess(w http.ResponseWriter)

JsonSuccess writes a success message to the writer.

func Mount

func Mount(r *mux.Router, path string, handler http.Handler)

Mount mounts a specific handler under a given path for mux.

func NotAllowedHandler

func NotAllowedHandler(w http.ResponseWriter, _ *http.Request)

NotAllowedHandler handles 405 responses

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, _ *http.Request)

NotFoundHandler handles 404 responses

Types

This section is empty.

Jump to

Keyboard shortcuts

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