Documentation
¶
Index ¶
- func EnsureCrumbHandler(cr Crumb, next_handler go_http.Handler) go_http.Handler
- func EnsureCrumbHandlerWithErrorHandler(cr Crumb, next_handler go_http.Handler, error_handler go_http.Handler) go_http.Handler
- func EnsureCrumbHandlerWithFaultWrapper(cr Crumb, next_handler go_http.Handler) go_http.Handler
- func Error(cl ErrorClass, err error) fault.FaultError
- func NewCrumbRewriteFunc(crumb_var string) rewrite.RewriteHTMLFunc
- func NewRandomEncryptedCrumbExtra() (string, error)
- func NewRandomEncryptedCrumbSecret() (string, error)
- func NewRandomEncryptedCrumbURI(ctx context.Context, ttl int, key string) (string, error)
- func RegisterCrumb(ctx context.Context, scheme string, f CrumbInitializeFunc) error
- func Schemes() []string
- func SchemesAsString() string
- type Crumb
- type CrumbError
- type CrumbInitializeFunc
- type EncryptedCrumb
- type ErrorClass
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnsureCrumbHandler ¶
EnsureCrumbHandler wraps 'next_handler' with a middleware `http.Handler` for assigning and validating crumbs using the default `fomuseum/go-http-fault/v2.FaultHandler` as an error handler. Any errors that trigger the error handler can be retrieved using `sfomuseum/go-http-fault/v2.RetrieveError()`.
func EnsureCrumbHandlerWithErrorHandler ¶
func EnsureCrumbHandlerWithErrorHandler(cr Crumb, next_handler go_http.Handler, error_handler go_http.Handler) go_http.Handler
EnsureCrumbHandlerWithErrorHandler wraps 'next_handler' with a middleware a middleware `http.Handler` for assigning and validating crumbs using a custom error handler. Any errors that trigger the error handler can be retrieved using `sfomuseum/go-http-fault/v2.RetrieveError()`.
func EnsureCrumbHandlerWithFaultWrapper ¶
EnsureCrumbHandlerWithFaultWrapper wraps 'next_handler' with a middleware `http.Handler` for assigning and validating crumbs. Error handling is assumed to be handled by a separate middleware handler provided by a `sfomuseum/go-http-fault/v2.FaultWrapper`. instance. Any errors that are triggered as recorded using the `sfomuseum/go-http-fault/v2.AssignError()` method and can be retrieved using `sfomuseum/go-http-fault/v2.RetrieveError()` method.
func Error ¶
func Error(cl ErrorClass, err error) fault.FaultError
New returns a new `CrumbError` instance.
func NewCrumbRewriteFunc ¶
func NewCrumbRewriteFunc(crumb_var string) rewrite.RewriteHTMLFunc
NewCrumbRewriteFunc returns a `aaronland/go-http-rewrite.RewriteHTMLFunc` used to append crumb data to HTML output.
func NewRandomEncryptedCrumbExtra ¶
NewRandomEncryptedCrumbExtra returns a random extra value suitable for `encrypted://` crumb URIs.
func NewRandomEncryptedCrumbSecret ¶
NewRandomEncryptedCrumbSecret returns a random salt value suitable for `encrypted://` crumb URIs.
func NewRandomEncryptedCrumbURI ¶
NewRandomEncryptedCrumbURI return a valid `aaronland/go-http-crumb` URI for an encrypted crumb whose key is 'key' and whose time to live is 'ttl'.
func RegisterCrumb ¶
func RegisterCrumb(ctx context.Context, scheme string, f CrumbInitializeFunc) error
RegisterCrumb registers 'scheme' with 'f' for URIs passed to the `NewCrumb` method.
func Schemes ¶
func Schemes() []string
Schemes returns the list of schemes that have registered for use with the `NewCrumb` method.
func SchemesAsString ¶
func SchemesAsString() string
SchemesAsString returns the list of schemes that have registered for use with the `NewCrumb` method as a string.
Types ¶
type Crumb ¶
type Crumb interface { // Generate return a new crumb string for an HTTP request. Generate(*http.Request, ...string) (string, error) // Generate validates a crumb string for an HTTP request. Validate(*http.Request, string, ...string) (bool, error) // Key returns the unique key used to generate a crumb. Key(*http.Request) string // Base returns the leading string used to generate a crumb. Base(*http.Request, ...string) (string, error) }
type Crumb is an interface for generating and validating HTTP crumb strings.
func NewDebugCrumb ¶
NewDebugCrumb returns a `EncryptedCrumb` instance with a randomly generated secret and salt valid for 5 minutes configured by 'uri' which should take the form of:
debug://?{QUERY_PARAMETERS}
Where '{QUERY_PARAMETERS}' may be: * `ttl={SECONDS}`. Default is 300
type CrumbError ¶
type CrumbError struct { fault.FaultError // contains filtered or unexported fields }
type CrumbError implements the `error` and `fault.FaultError` interfaces for application specific errors.
func (CrumbError) Error ¶
func (e CrumbError) Error() string
String returns an informative string message to be displayed in a public setting.
func (CrumbError) Private ¶
func (e CrumbError) Private() error
Returns the string value of 'e' and of the error passed to 'e' when it was instantiated, if present. These are considered detailed errors not necesarily meant for the general public.
func (CrumbError) Public ¶
func (e CrumbError) Public() error
String returns an informative string message to be displayed in a public setting.
func (CrumbError) Unwrap ¶
func (e CrumbError) Unwrap() error
Unwrap returns the error passed to 'e' when it was instantiated.
type CrumbInitializeFunc ¶
type CrumbInitializeFunc is a function used to initialize packages that implement the `Crumb` interface.
type EncryptedCrumb ¶
type EncryptedCrumb struct { Crumb // contains filtered or unexported fields }
type EncryptedCrumb implements the Crumb interface for crumb strings that are encrypted.
type ErrorClass ¶
type ErrorClass string
type ErrorClass defines application specific error classes (or types)
const ExpiredCrumb ErrorClass = "Crumb has expired."
ExpiredCrumb defines an ErrorClass for crumbs that have expired.
const GenerateCrumb ErrorClass = "Unable to generate crumb"
GenerateCrumb defines an ErrorClass for crumbs that are not able to be generated.
const InvalidCrumb ErrorClass = "Crumb does not validate."
InvalidCrumb defines an ErrorClass for crumbs that do not validate.
const MissingCrumb ErrorClass = "Crumb is missing."
MissingCrumb defines an ErrorClass for crumbs that are missing
const UnsanitizedCrumb ErrorClass = "Crumb supplied is invalid."
UnsanitizedCrumb defines an ErrorClass for crumbs that have failed input validation.