Documentation
¶
Index ¶
- Constants
- func Default(session *sessions.Session, name string, def interface{}) interface{}
- func JSON(w http.ResponseWriter, r *http.Request, code int, data interface{}) error
- func RenewSessionID(w http.ResponseWriter, r *http.Request, session *sessions.Session) *sessions.Session
- type Anonymous
- type BindingResult
- type Logger
- type Minion
- func (m *Minion) GetPrincipal(r *http.Request) Principal
- func (m *Minion) HTML(w http.ResponseWriter, r *http.Request, code int, name string, data V)
- func (m *Minion) JSON(w http.ResponseWriter, r *http.Request, code int, data interface{})
- func (m *Minion) LoadTemplates() error
- func (m *Minion) Secured(fn http.HandlerFunc, roles ...string) http.HandlerFunc
- type NilStore
- type Option
- type Principal
- type V
Constants ¶
const ( // PrincipalKey is the key used for the principal in the user session. PrincipalKey = "_principal" // RedirectKey is the key used for the original URL before redirecting to the login site. RedirectKey = "_redirect" )
Variables ¶
This section is empty.
Functions ¶
func Default ¶
Default retrieves a value from the given session. If the value does not exist in the session, a provided default is returned
func RenewSessionID ¶
Types ¶
type Anonymous ¶
type Anonymous struct{}
Anonymous implements the Principal interface for unauthenticated users and can be used as a fallback principal when none is set in the current session.
func (Anonymous) Authenticated ¶
Authenticated returns always false, because Anonymous users are not authenticated.
func (Anonymous) HasAnyRole ¶
HasAnyRole returns always false for any role, because Anonymous users are not authenticated.
type BindingResult ¶
BindingResult holds validation errors of the binding process from a HTML form to a Go struct.
func (BindingResult) Fail ¶
func (br BindingResult) Fail(field, err string)
Fail marks the binding as failed and stores an error for the given field that caused the form binding to fail.
func (BindingResult) Include ¶
func (br BindingResult) Include(other BindingResult)
Include copies all errors and state of a binding result
func (BindingResult) Valid ¶
func (br BindingResult) Valid() bool
Valid returns whether the binding was successfull or not.
type Logger ¶
type Logger interface {
Printf(fmt string, v ...interface{})
}
Logger is a simple interface to describe something that can write log output.
type Minion ¶
type Minion struct { Debug bool Logger Logger // Unauthorized is called for Secured handlers where no authenticated // principal is found in the current session. The default handler will // redirect the user to `UnauthorizedURL` and store the original URL // in the session. // Forbidden is called for Secured handlers where an authenticated principal // does not have enough permission to view the resource. The default handler // will execute the HTML template `ForbiddenTemplate`. Forbidden func(w http.ResponseWriter, r *http.Request) ForbiddenTemplate string // Error is called for any error that occur during the request processing, be // it client side errors (4xx status) or server side errors (5xx status). The // default handler will execute the HTML template `ErrorTemplate`. Error func(w http.ResponseWriter, r *http.Request, code int, err error) ErrorTemplate string Sessions sessions.Store SessionName string Templates *template.Template TemplateFuncMap template.FuncMap }
Minion implements basic building blocks that most http servers require
func (*Minion) GetPrincipal ¶
GetPrincipal returns the principal from the current session.
func (*Minion) LoadTemplates ¶
LoadTemplates loads the html/template files from the filesystem.
func (*Minion) Secured ¶
func (m *Minion) Secured(fn http.HandlerFunc, roles ...string) http.HandlerFunc
Secured requires that the user has at least one of the provided roles before the request is forwarded to the secured handler.
type Option ¶
Option is a functional configuration type that can be used to tailor the Minion instance during creation.