2015-05-04 12:04:17 -05:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2016-04-15 15:21:55 -05:00
|
|
|
"crypto/tls"
|
2015-05-04 12:04:17 -05:00
|
|
|
"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 00:58:08 -05:00
|
|
|
// The host address to bind on - defaults to (virtual) Host if empty
|
|
|
|
BindHost string
|
2015-05-04 23:38:49 -05:00
|
|
|
|
2015-05-04 12:04:17 -05:00
|
|
|
// The port to listen on
|
|
|
|
Port string
|
|
|
|
|
2016-01-03 18:41:29 -05:00
|
|
|
// The protocol (http/https) to serve with this config; only set if user explicitly specifies it
|
|
|
|
Scheme string
|
|
|
|
|
2015-05-04 12:04:17 -05:00
|
|
|
// The directory from which to serve files
|
|
|
|
Root string
|
|
|
|
|
|
|
|
// HTTPS configuration
|
|
|
|
TLS TLSConfig
|
|
|
|
|
2016-02-17 20:11:03 -05:00
|
|
|
// Middleware stack
|
|
|
|
Middleware []middleware.Middleware
|
2015-05-04 12:04:17 -05:00
|
|
|
|
2015-11-10 21:46:18 -05: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-04 12:04:17 -05:00
|
|
|
Startup []func() error
|
|
|
|
|
2015-11-10 21:46:18 -05: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-04 12:04:17 -05: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-04 17:23:16 -05:00
|
|
|
|
|
|
|
// The name of the application
|
|
|
|
AppName string
|
|
|
|
|
|
|
|
// The application's version
|
|
|
|
AppVersion string
|
2015-05-04 12:04:17 -05: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-16 12:38:56 -05:00
|
|
|
// TLSConfig describes how TLS should be configured and used.
|
2015-05-04 12:04:17 -05:00
|
|
|
type TLSConfig struct {
|
2016-02-12 15:04:24 -05:00
|
|
|
Enabled bool // will be set to true if TLS is enabled
|
2016-02-11 02:06:05 -05:00
|
|
|
LetsEncryptEmail string
|
2016-02-12 15:04:24 -05:00
|
|
|
Manual bool // will be set to true if user provides own certs and keys
|
2016-02-16 01:39:04 -05:00
|
|
|
Managed bool // will be set to true if config qualifies for implicit automatic/managed HTTPS
|
2016-02-12 15:04:24 -05:00
|
|
|
OnDemand bool // will be set to true if user enables on-demand TLS (obtain certs during handshakes)
|
2015-05-21 11:37:39 -05:00
|
|
|
Ciphers []uint16
|
|
|
|
ProtocolMinVersion uint16
|
|
|
|
ProtocolMaxVersion uint16
|
|
|
|
PreferServerCipherSuites bool
|
2015-06-02 00:22:11 -05:00
|
|
|
ClientCerts []string
|
2016-04-15 15:21:55 -05:00
|
|
|
ClientAuth tls.ClientAuthType
|
2015-05-04 12:04:17 -05:00
|
|
|
}
|