server

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package server implements a configurable, general-purpose web server. It relies on configurations obtained from the adjacent config package and can execute middleware as defined by the adjacent middleware package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorFunc added in v0.7.2

func DefaultErrorFunc(w http.ResponseWriter, r *http.Request, status int)

func ListenAndServeTLSWithSNI

func ListenAndServeTLSWithSNI(srv *http.Server, tlsConfigs []TLSConfig) error

ListenAndServeTLSWithSNI serves TLS with Server Name Indication (SNI) support, which allows multiple sites (different hostnames) to be served from the same address. This method is adapted directly from the std lib's net/http ListenAndServeTLS function, which was written by the Go Authors. It has been modified to support multiple certificate/key pairs.

Types

type Config added in v0.6.0

type Config struct {
	// The hostname or IP on which to serve
	Host string

	// The host address to bind on - defaults to (virtual) Host if empty
	BindHost string

	// The port to listen on
	Port string

	// The directory from which to serve files
	Root string

	// HTTPS configuration
	TLS TLSConfig

	// Middleware stack; map of path scope to middleware -- TODO: Support path scope?
	Middleware map[string][]middleware.Middleware

	// Functions (or methods) to execute at server start; these
	// are executed before any parts of the server are configured,
	// and the functions are blocking
	Startup []func() error

	// Functions (or methods) to execute when the server quits;
	// these are executed in response to SIGINT and are blocking
	Shutdown []func() error

	// The path to the configuration file from which this was loaded
	ConfigFile string

	// The name of the application
	AppName string

	// The application's version
	AppVersion string
}

Config configuration for a single server.

func (Config) Address added in v0.6.0

func (c Config) Address() string

Address returns the host:port of c as a string.

type Server

type Server struct {
	HTTP2 bool // temporary while http2 is not in std lib (TODO: remove flag when part of std lib)
	// contains filtered or unexported fields
}

Server represents an instance of a server, which serves static content at a particular address (host and port).

func New

func New(addr string, configs []Config) (*Server, error)

New creates a new Server which will bind to addr and serve the sites/hosts configured in configs. This function does not start serving.

func (*Server) Serve

func (s *Server) Serve() error

Serve starts the server. It blocks until the server quits.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the entry point for every request to the address that s is bound to. It acts as a multiplexer for the requests hostname as defined in the Host header so that the correct virtualhost (configuration and middleware stack) will handle the request.

type TLSConfig added in v0.6.0

type TLSConfig struct {
	Enabled                  bool
	Certificate              string
	Key                      string
	Ciphers                  []uint16
	ProtocolMinVersion       uint16
	ProtocolMaxVersion       uint16
	PreferServerCipherSuites bool
	ClientCerts              []string
}

TLSConfig describes how TLS should be configured and used, if at all. A certificate and key are both required. The rest is optional.

Jump to

Keyboard shortcuts

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