minion

package module
v0.0.0-...-d91d97c Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 11 Imported by: 2

README

minion

** This project is deprecated. ** Please check out the Minions repo

Documentation

Index

Constants

View Source
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

func Default(session *sessions.Session, name string, def interface{}) interface{}

Default retrieves a value from the given session. If the value does not exist in the session, a provided default is returned

func JSON

func JSON(w http.ResponseWriter, r *http.Request, code int, data interface{}) error

JSON outputs the data encoded as JSON.

func RenewSessionID

func RenewSessionID(w http.ResponseWriter, r *http.Request, session *sessions.Session) *sessions.Session

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

func (a Anonymous) Authenticated() bool

Authenticated returns always false, because Anonymous users are not authenticated.

func (Anonymous) HasAnyRole

func (a Anonymous) HasAnyRole(roles ...string) bool

HasAnyRole returns always false for any role, because Anonymous users are not authenticated.

func (Anonymous) ID

func (a Anonymous) ID() string

ID retunrs always the string `anonymous` as ID for unauthenticated users.

type BindingResult

type BindingResult map[string]string

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.
	Unauthorized    func(w http.ResponseWriter, r *http.Request)
	UnauthorizedURL string

	// 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 NewMinion

func NewMinion(options ...Option) *Minion

NewMinion creates a new minion instance.

func (*Minion) GetPrincipal

func (m *Minion) GetPrincipal(r *http.Request) Principal

GetPrincipal returns the principal from the current session.

func (*Minion) HTML

func (m *Minion) HTML(w http.ResponseWriter, r *http.Request, code int, name string, data V)

HTML outputs a rendered HTML template to the client.

func (*Minion) JSON

func (m *Minion) JSON(w http.ResponseWriter, r *http.Request, code int, data interface{})

JSON outputs the data encoded as JSON.

func (*Minion) LoadTemplates

func (m *Minion) LoadTemplates() error

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 NilStore

type NilStore struct{}

func (NilStore) Get

func (store NilStore) Get(r *http.Request, name string) (*sessions.Session, error)

func (NilStore) New

func (store NilStore) New(r *http.Request, name string) (*sessions.Session, error)

func (NilStore) Save

func (store NilStore) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error

type Option

type Option func(*Minion) *Minion

Option is a functional configuration type that can be used to tailor the Minion instance during creation.

type Principal

type Principal interface {
	Authenticated() bool
	ID() string
	HasAnyRole(roles ...string) bool
}

Principal is an entity that can be authenticated and verified.

type V

type V map[string]interface{}

V is a helper type to quickly build variable maps for templates.

func (V) MarshalJSON

func (v V) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

Jump to

Keyboard shortcuts

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