common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2018 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashKeySize is optimally 64 bytes
	HashKeySize = 64
	// BlockKeySize is optimally 32 bytes
	BlockKeySize = 32
)

Variables

This section is empty.

Functions

func Decode

func Decode(hash string) ([]byte, error)

Decode extracts a byte slice from a base64 encoded string.

func Generate

func Generate(keysize int) string

Generate creates a random key of keysize length, and returns it in base64 encoded text.

func GetUsername added in v0.0.7

func GetUsername(ctx context.Context) string

GetUsername retrieves authenticated username from Context

func JSONResponse

func JSONResponse(w http.ResponseWriter, o interface{})

JSONResponse writes the interface{} o as a JSON object response body.

func JSONStatusResponse

func JSONStatusResponse(code int, w http.ResponseWriter, o interface{})

JSONStatusResponse writes the interface{} o as a JSON object response body with the givent http status code.

func MatchingFiles added in v0.2.0

func MatchingFiles(dir string, extensions ...string) []string

MatchingFiles returns the names of all the files in dir with (case insensitive) extension matching one of extensions.

func NewStaticFileHandler added in v0.2.0

func NewStaticFileHandler(filenames ...string) http.Handler

NewStaticFileHandler tries each filename parameter and serves the first one successfully read, or returns 404 if none are found.

func NewTemplateHandler added in v0.2.0

func NewTemplateHandler(filenames ...string) http.Handler

NewTemplateHandler loads each filename parameter as a template, and serves the first one to match, or returns 404 if one is not found.

func QueryParamKeys

func QueryParamKeys(v url.Values) []string

QueryParamKeys gets the keys from a url.Values collection.

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, targetURL string, additionalParams map[string]string)

Redirect initiates an http redirect response.

func SetUsername added in v0.0.7

func SetUsername(ctx context.Context, username string) context.Context

SetUsername returns a context with the given username set

Types

type KeyProvider added in v0.0.7

type KeyProvider interface {
	Hash() []byte
	Block() []byte
}

KeyProvider describes functions needed for encrypted cookies.

func DefaultKeyProvider added in v0.0.7

func DefaultKeyProvider() (KeyProvider, error)

DefaultKeyProvider creates random default values for the provider. This is only good for one execution run, unless the generated keys are persisted.

func NewKeyProvider added in v0.0.7

func NewKeyProvider(hash string, block string) (KeyProvider, error)

NewKeyProvider creates a default provider from base64 encoded values.

type Middleware added in v0.1.0

type Middleware interface {
	ServeHTTP(http.ResponseWriter, *http.Request, http.HandlerFunc)
}

Middleware describes common middleware

func NewDebugMiddleware

func NewDebugMiddleware(w io.Writer, verbose bool) Middleware

NewDebugMiddleware provides middleware suitable for exhaustive request/response logging.

type PasswordChecker added in v0.0.7

type PasswordChecker interface {
	IsAuthenticated(username string, password string) bool
}

PasswordChecker describes functionality to verify passwords

func PasswordCheckers added in v0.0.7

func PasswordCheckers(checkers ...PasswordChecker) PasswordChecker

PasswordCheckers combines multiple PasswordCheckers

type RequestChecker added in v0.0.7

type RequestChecker interface {
	IsAuthenticated(r *http.Request) string
}

RequestChecker describes functionality to verify requests

func RequestCheckers added in v0.0.7

func RequestCheckers(checkers ...RequestChecker) RequestChecker

RequestCheckers combines multiple RequestCheckers

Jump to

Keyboard shortcuts

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