web

package
v0.0.0-...-64a0d4e Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2017 License: BSD-3-Clause Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ComponentContextKey = "component"

ComponentContextKey is a key for the Request context that returns the Component instance serving the request.

Functions

func ForceSecureMiddleware

func ForceSecureMiddleware(next http.Handler) http.Handler

ForceSecureMiddleware will redirect requests to their HTTPS equivalent if HTTPS has been configured for the component.

func Register

func Register(reg *objects.Registry) error

Register will register an instance of Component with a com.Registry

func StaticFileMiddleware

func StaticFileMiddleware(next http.Handler) http.Handler

StaticFileMiddleware serves static files based on component configuration of StaticPath and StaticDir.

Types

type Component

type Component struct {
	Log        log.Logger         `com:"singleton"`
	Handlers   []Handler          `com:"extpoint"`
	Middleware MiddlewareInjector `com:"singleton"`

	Config
	// contains filtered or unexported fields
}

Component for web serving

func FromRequest

func FromRequest(r *http.Request) *Component

func (*Component) InitializeConfig

func (c *Component) InitializeConfig(cfg config.Settings) error

InitializeConfig sets up defaults and unmarshals into Config embedded in Component

func (*Component) InitializeDaemon

func (c *Component) InitializeDaemon() error

InitializeDaemon will attempt to setup a TLSCertReloader if TLSCertPath is configured.

func (*Component) Serve

func (c *Component) Serve()

Serve starts listening and serving HTTP and HTTPS if configured

func (*Component) ServeHTTP

func (c *Component) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP wraps the Handler protocol and injects middleware

func (*Component) Stop

func (c *Component) Stop()

Stop will shutdown any HTTP servers

type Config

type Config struct {
	// Address and port to listen on
	ListenAddr string

	// Directory to serve static files from
	StaticDir string

	// URL path to serve static files at
	StaticPath string

	// Random string to use for session cookies
	CookieSecret string

	// Address and port to listen for TLS on
	TLSAddr string

	// Path to TLS cert file
	TLSCertPath string

	// Path to TLS key file
	TLSKeyPath string
}

Config is the configuration for Component

type Handler

type Handler interface {
	// MatchHTTP returns true when a Request should be handled by this object
	MatchHTTP(r *http.Request) bool

	// ServeHTTP handles the Request if MatchHTTP returns true
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Handler extension API for matching and handling HTTP requests

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware handler API

type MiddlewareInjector

type MiddlewareInjector interface {
	// Middleware returns a list of middleware in the order of outer first
	Middleware() []Middleware
}

MiddlewareInjector defines ordered HTTP middleware to use

type TLSCertReloader

type TLSCertReloader struct {
	sync.Mutex
	// contains filtered or unexported fields
}

TLSCertReloader is a TLS certificate provider that can reload certificates from disk. This is used when a TLS cert is configured, with Reload called once an hour. This means updating the cert and key on disk will start being used within an hour without needing to restart the server.

func NewTLSCertReloader

func NewTLSCertReloader(certPath, keyPath string) (*TLSCertReloader, error)

NewTLSCertReloader returns a new NewTLSCertReloader after an initial call to Reload, which could return an error.

func (*TLSCertReloader) GetCertificate

func (cr *TLSCertReloader) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate is used with tls.Config to provide a tls.Certificate

func (*TLSCertReloader) Reload

func (cr *TLSCertReloader) Reload() error

Reload performs a simple tls.LoadX509KeyPair with the given paths and atomically makes it available via the

Directories

Path Synopsis
init
Package init is used to register the auth component with the default registry via side effect import.
Package init is used to register the auth component with the default registry via side effect import.
init
Package init is used to register the console component with the default registry via side effect import.
Package init is used to register the console component with the default registry via side effect import.
Package init is used to register the web component with the default registry via side effect import.
Package init is used to register the web component with the default registry via side effect import.
init
Package init is used to register the sessions component with the default registry via side effect import.
Package init is used to register the sessions component with the default registry via side effect import.

Jump to

Keyboard shortcuts

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