Documentation
¶
Index ¶
- Constants
- func HandleCurrentUser() http.HandlerFunc
- func HandleLogin(db database.Instance, repo cache.Repository) http.HandlerFunc
- func HandleLogout(repo cache.Repository) http.HandlerFunc
- func IfAllowed(e *policy.Enforcer, query string) func(next http.Handler) http.Handler
- func IfPossible(e *policy.Enforcer, query string, unknowns []string) func(next http.Handler) http.Handler
- func Mount(db database.Instance, e *policy.Enforcer, repo cache.Repository) http.Handler
- func WithSession(repo cache.Repository, required bool) func(next http.Handler) http.Handler
- type ContextField
Constants ¶
const ( // SQLColumns the context key to store and retrieve the SQL fields permitted // to access by the partial policy query. SQLColumns = ContextField("sql fields") // SQLClause the context key to store and retrieve the SQL where clause // from a partial policy query. SQLClause = ContextField("sql clause") // SQLValues the context key to store and retrieve the SQL where clause // values from a partial policy query. SQLValues = ContextField("sql values") )
const ( // CurrentUser is the context key to store and retrieve the current logged in // user. CurrentUser = ContextField("user") )
const (
// SessionCookie is the name of the session cookie.
SessionCookie = "session"
)
Variables ¶
This section is empty.
Functions ¶
func HandleCurrentUser ¶
func HandleCurrentUser() http.HandlerFunc
HandleCurrentUser returns the user as stored in the context. Basically it returns the user associated with the active session.
func HandleLogin ¶
func HandleLogin(db database.Instance, repo cache.Repository) http.HandlerFunc
HandleLogin is a request handler that checks credentials, and starts a session for an authorized user.
func HandleLogout ¶
func HandleLogout(repo cache.Repository) http.HandlerFunc
func IfAllowed ¶
IfAllowed is a middleware that allows/denies access to the handler based on the policy. This is an all-or-nothing evaluation.
func IfPossible ¶
func IfPossible(e *policy.Enforcer, query string, unknowns []string) func(next http.Handler) http.Handler
IfPossible is a middleware policy enforcer that can execute partial evaluations. If an action _could_ be permitted, the context will reflect which SQL fields are accessible, and contain a WHERE clause with values. The handler can use this information to restrict the SQL statement.
func WithSession ¶
Types ¶
type ContextField ¶
type ContextField string
ContextField is a string type for storing auth fields in the context.