2015-05-05 01:04:17 +08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/mholt/caddy/middleware"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config configuration for a single server.
|
|
|
|
type Config struct {
|
|
|
|
// The hostname or IP on which to serve
|
|
|
|
Host string
|
|
|
|
|
2015-05-05 13:58:08 +08:00
|
|
|
// The host address to bind on - defaults to (virtual) Host if empty
|
|
|
|
BindHost string
|
2015-05-05 12:38:49 +08:00
|
|
|
|
2015-05-05 01:04:17 +08:00
|
|
|
// The port to listen on
|
|
|
|
Port string
|
|
|
|
|
2016-01-04 07:41:29 +08:00
|
|
|
// The protocol (http/https) to serve with this config; only set if user explicitly specifies it
|
|
|
|
Scheme string
|
|
|
|
|
2015-05-05 01:04:17 +08:00
|
|
|
// 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
|
|
|
|
|
2015-11-11 10:46:18 +08:00
|
|
|
// Startup is a list of functions (or methods) to execute at
|
|
|
|
// server startup and restart; these are executed before any
|
|
|
|
// parts of the server are configured, and the functions are
|
|
|
|
// blocking. These are good for setting up middlewares and
|
|
|
|
// starting goroutines.
|
2015-05-05 01:04:17 +08:00
|
|
|
Startup []func() error
|
|
|
|
|
2015-11-11 10:46:18 +08:00
|
|
|
// FirstStartup is like Startup but these functions only execute
|
|
|
|
// during the initial startup, not on subsequent restarts.
|
|
|
|
//
|
|
|
|
// (Note: The server does not ever run these on its own; it is up
|
|
|
|
// to the calling application to do so, and do so only once, as the
|
|
|
|
// server itself has no notion whether it's a restart or not.)
|
|
|
|
FirstStartup []func() error
|
|
|
|
|
2015-05-05 01:04:17 +08:00
|
|
|
// 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
|
2015-05-05 06:23:16 +08:00
|
|
|
|
|
|
|
// The name of the application
|
|
|
|
AppName string
|
|
|
|
|
|
|
|
// The application's version
|
|
|
|
AppVersion string
|
2015-05-05 01:04:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Address returns the host:port of c as a string.
|
|
|
|
func (c Config) Address() string {
|
|
|
|
return net.JoinHostPort(c.Host, c.Port)
|
|
|
|
}
|
|
|
|
|
2015-10-17 01:38:56 +08:00
|
|
|
// TLSConfig describes how TLS should be configured and used.
|
2015-05-05 01:04:17 +08:00
|
|
|
type TLSConfig struct {
|
2016-01-04 07:41:29 +08:00
|
|
|
Enabled bool
|
|
|
|
Certificate string
|
|
|
|
Key string
|
|
|
|
LetsEncryptEmail string
|
2016-01-07 07:04:08 +08:00
|
|
|
Managed bool // will be set to true if config qualifies for automatic, managed TLS
|
2016-01-04 07:41:29 +08:00
|
|
|
//DisableHTTPRedir bool // TODO: not a good idea - should we really allow it?
|
2015-10-24 10:36:54 +08:00
|
|
|
OCSPStaple []byte
|
2015-05-22 00:37:39 +08:00
|
|
|
Ciphers []uint16
|
|
|
|
ProtocolMinVersion uint16
|
|
|
|
ProtocolMaxVersion uint16
|
|
|
|
PreferServerCipherSuites bool
|
2015-06-02 13:22:11 +08:00
|
|
|
ClientCerts []string
|
2015-05-05 01:04:17 +08:00
|
|
|
}
|