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 FileServer ¶
func FileServer(root http.FileSystem, hide []string) middleware.Handler
FileServer is adapted from the one in net/http by the Go authors. Significant modifications have been made.
License:
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
func ListenAndServeTLSWithSNI ¶
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.
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 ¶
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) 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.