common

package
v0.0.0-...-5c97048 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomBytes

func RandomBytes(n int) []byte

RandomBytes returns n bytes from crypt/rand.Reader.

func WeakRandomSource

func WeakRandomSource() *rand.Rand

WeakRandomSource returns a weak math/rand RNG (non-crypto-grade) initialized with a random seed.

func WithDynamicHeaders

func WithDynamicHeaders(h http.Handler, csp string) http.Handler

WithDynamicHeaders wraps an http.Handler with cache-busting and security-related headers appropriate for a user-facing dynamic application. The 'csp' argument sets a default Content-Security-Policy.

Types

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

A Renderer just renders HTML templates with some common context variables. Context is represented as a map[string]interface{}, to allow the merge operation.

func NewRenderer

func NewRenderer(tpl *template.Template, vars map[string]interface{}) *Renderer

NewRenderer creates a new Renderer with the provided templates and default variables.

func (*Renderer) Render

func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, templateName string, data map[string]interface{})

Render the named HTML template to 'w'.

type SessionAuthenticationKey

type SessionAuthenticationKey YAMLBytes

SessionAuthenticationKey is a binary type for gorilla.session authentication keys, that is YAML-unserializable.

func (*SessionAuthenticationKey) UnmarshalYAML

func (k *SessionAuthenticationKey) UnmarshalYAML(value *yaml.Node) error

type SessionEncryptionKey

type SessionEncryptionKey YAMLBytes

SessionEncryptionKey is a binary type for gorilla.session encryption keys, that is YAML-unserializable.

func (*SessionEncryptionKey) UnmarshalYAML

func (k *SessionEncryptionKey) UnmarshalYAML(value *yaml.Node) error

type URLMap

type URLMap interface {
	URLFor(string) string
	Resolve(string) string
}

URLMap is an interface between our logical view of application URLs and the user's. The only implementation allows us to serve the app below its own URL path prefix.

func NewURLPathPrefix

func NewURLPathPrefix(prefix string) URLMap

NewURLPathPrefix creates a URLMap where everything is served under a path prefix.

type YAMLBytes

type YAMLBytes []byte

YAMLBytes is a []byte slice that can be safely unmarshaled from YAML. For the time being, the value is just decoded as-is, but for full binary blob support we might switch to expect base64-encoding.

func (*YAMLBytes) UnmarshalYAML

func (b *YAMLBytes) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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