Documentation
¶
Index ¶
- Constants
- Variables
- func BaseHeaders(h http.Handler) http.Handler
- func NoopHandler(h http.Handler) http.Handler
- func TemplateFuncs(ctx context.Context, addlFuncs template.FuncMap) template.FuncMap
- type BrowserHandlerFunc
- type BrowserResponse
- type CommonResponse
- type Config
- type HandlerOpt
- type JSONResponse
- type NilResponse
- type RedirectResponse
- type Request
- func (b *Request) Cookie(name string) (*http.Cookie, error)
- func (b *Request) DecodeForm(target any) error
- func (b *Request) PathValue(name string) string
- func (b *Request) PostForm() url.Values
- func (b *Request) RawRequest() *http.Request
- func (b *Request) Session() *session.Session
- func (b *Request) URL() *url.URL
- func (b *Request) UnmarshalJSONBody(target any) error
- type ResponseWriter
- type Server
- func (s *Server) Handle(pattern string, h http.Handler, opts ...HandlerOpt)
- func (s *Server) HandleFunc(pattern string, h func(w http.ResponseWriter, r *http.Request), ...)
- func (s *Server) HandleRaw(pattern string, handler http.Handler)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type TemplateResponse
Constants ¶
const ( MiddlewareCSPName = "csp" MiddlewareCSRFName = "csrf" MiddlewareRequestIDName = "requestid" MiddlewareRequestLogName = "requestlog" MiddlewareSessionName = "session" MiddlewareErrorName = "error" MiddlewareStaticName = "static" MiddlewareBaseHeadersName = "baseheaders" )
Variables ¶
var DefaultCSPOpts = []csp.HandlerOpt{ csp.DefaultSrc(`'none'`), csp.WithScriptNonce(), csp.WithStyleNonce(), csp.ImgSrc(`'self'`), csp.ConnectSrc(`'self'`), csp.FontSrc(`'self'`), csp.BaseURI(`'self'`), csp.FrameAncestors(`'none'`), }
Functions ¶
func BaseHeaders ¶
BaseHeaders sets basic security headers for all requests: - X-Frame-Options: SAMEORIGIN - X-XSS-Protection: 1; mode=block - X-Content-Type-Options: nosniff
func NoopHandler ¶
NoopHandler can be used to explicitly opt-out of a handler.
Types ¶
type BrowserHandlerFunc ¶
type BrowserHandlerFunc func(context.Context, ResponseWriter, *Request) error
func (BrowserHandlerFunc) ServeHTTP ¶
func (b BrowserHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
type BrowserResponse ¶
type BrowserResponse interface {
// contains filtered or unexported methods
}
type CommonResponse ¶
type Config ¶
type Config struct {
BaseURL *url.URL
SessionManager *session.Manager
ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
Static fs.FS
CSPOpts []csp.HandlerOpt
// ScriptNonce indicates that a nonce should be used for inline scripts.
// This will update the CSP, and the template func will return a value.
ScriptNonce bool
// ScriptNonce indicates that a nonce should be used for inline styles. This
// will update the CSP, and the template func will return a value.
StyleNonce bool
// AdditionalBrowserMiddleware is a set of middleware that will be added to
// all browser handlers, after the base middleware.
AdditionalBrowserMiddleware []func(http.Handler) http.Handler
/* start new section */
CSRFHandler func(http.Handler) http.Handler
}
type HandlerOpt ¶
HandlerOpt are functions that can be used to provide options to middleware serving a request. When registered on a handler, they will be called before the request hits the middleware stack.
type JSONResponse ¶
type JSONResponse struct {
CommonResponse
// Data to be marshaled to JSON
Data any
}
type NilResponse ¶
type NilResponse struct {
CommonResponse
}
NilResponse indicates that no action should be taken. This should be used if the response was handled directly.
type RedirectResponse ¶
type RedirectResponse struct {
CommonResponse
// Code for redirect. If not set, http.StatusSeeOther(303) will be used
Code int
// URL to redirect to
URL string
}
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequestFrom ¶
func (*Request) DecodeForm ¶
DecodeForm unpacks the POST form into the target. The target type should be tagged appropriately.
func (*Request) RawRequest ¶
RawRequest returns the raw http.Request underlying this request.
func (*Request) UnmarshalJSONBody ¶
type ResponseWriter ¶
type ResponseWriter interface {
http.ResponseWriter
WriteResponse(r *Request, resp BrowserResponse) error
}
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) ResponseWriter
NewResponseWriter creates a new ResponseWriter
type Server ¶
type Server struct {
BrowserMux *http.ServeMux
BrowserMiddleware *middleware.Chain
RawMux *http.ServeMux
BaseMiddleware *middleware.Chain
HTTPServer *http.Server
// contains filtered or unexported fields
}
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(pattern string, h func(w http.ResponseWriter, r *http.Request), opts ...HandlerOpt)
type TemplateResponse ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cors provides a middleware to handle CORS pre-flight requests.
|
Package cors provides a middleware to handle CORS pre-flight requests. |
|
Package requestid allows the generation and propagation of request ID's via context, and HTTP calls.
|
Package requestid allows the generation and propagation of request ID's via context, and HTTP calls. |