web

package
v0.0.0-...-3c0849d Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IsDev bool

IsDev indicates whether we're running on a dev machine.

View Source
var Mux *goji.Mux

Mux is the root Mux for handling requests.

Functions

func EnsureHost

func EnsureHost(host string)

EnsureHost checks the request headers to ensure that it's an HTTPS request to the specified host. If not, it'll redirect the request to the same path on the specified host and using HTTPS. The check will also add the HSTS header for valid requests.

This function will do nothing when running on a dev machine.

func GetSignedCookieValue

func GetSignedCookieValue(s string) string

GetSignedCookieValue checks that the given string is appropriately signed with the secret.CookieSigningKey, that it is still valid, and returns the unpacked value.

func GetXSRF

func GetXSRF(r *http.Request) string

GetXSRF returns the XSRF value from the given request. It returns an empty string if the value doesn't exist or is invalid.

func HandleGet

func HandleGet(pattern string, h func(http.ResponseWriter, *http.Request), opts ...Option)

HandleGet adds a new GET route to the root Mux.

func HandlePost

func HandlePost(pattern string, h func(http.ResponseWriter, *http.Request), opts ...Option)

HandlePost adds a new POST route to the root Mux.

func InternalServerError

func InternalServerError(w http.ResponseWriter, err error)

InternalServerError sets the http 500 status code.

func Wildcard

func Wildcard(r *http.Request) string

Wildcard returns the matched wildcard component of the route.

Types

type Option

type Option func(*cfg)

Option represents a middleware option.

func NoCache

func NoCache(duration time.Duration) Option

NoCache will set clearing cache headers on a successful response.

func PrivateCache

func PrivateCache(duration time.Duration) Option

PrivateCache will set private cache headers on a successful response.

func PublicCache

func PublicCache(duration time.Duration) Option

PublicCache will set public cache headers on a successful response.

func XSRF

func XSRF() Option

XSRF will set an XSRF cookie header on GET requests and check it against form data on POST requests.

Jump to

Keyboard shortcuts

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