Documentation ¶
Overview ¶
Package middleware contains the HTTP middleware used in the api as well as utility functions for interacting with them
Index ¶
- Variables
- func CORS(next http.Handler) http.Handler
- func ContentHeaders(next http.Handler) http.Handler
- func GetUserSession(r *http.Request) *models.User
- func Logger(next http.Handler) http.Handler
- func RefreshSession(r *http.Request) error
- func SetUserSession(u models.User, w http.ResponseWriter) error
- type Chain
- type LoggedResponseWriter
- type Middleware
Constants ¶
This section is empty.
Variables ¶
var Default = Chain{ ContentHeaders, Logger, }
Default is the default middleware stack for Praelatus
Functions ¶
func CORS ¶
CORS allows cross origin requests to the server. Note: By default it allows all origins so can be insecure. TODO: Make the origins configurable
func ContentHeaders ¶
ContentHeaders will set the content-type header for the API to application/json
func GetUserSession ¶
GetUserSession will check the given http.Request for a session token and if found it will return the corresponding user.
func Logger ¶
Logger will log a request and any information about the request, it should be the first middleware in any chain.
func RefreshSession ¶
RefreshSession will reset the expiry on the session for the given request
func SetUserSession ¶
func SetUserSession(u models.User, w http.ResponseWriter) error
SetUserSession will generate a secure cookie for user u, will set the cookie on the response w and will add the user session to the session store
Types ¶
type LoggedResponseWriter ¶
type LoggedResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
LoggedResponseWriter wraps http.ResponseWriter so we can capture the status code for logging
func (*LoggedResponseWriter) Status ¶
func (w *LoggedResponseWriter) Status() int
Status will return the status code used in this request.
func (*LoggedResponseWriter) WriteHeader ¶
func (w *LoggedResponseWriter) WriteHeader(code int)
WriteHeader implements http.ResponseWriter adding our custom functionality to it