Documentation ¶
Index ¶
- func NewBasicAutocertManager(domains ...string) *autocert.Manager
- type Builder
- func WithHTTP(bind string) Builder
- func WithHTTPS(bind string, key string, cert string) Builder
- func WithLetsEncrypt(httpChallenge bool, domains ...string) Builder
- func WithLetsEncryptManager(manager *autocert.Manager, cfg *tls.Config, httpChallenge bool) Builder
- func WithTLS(bind string, key string, cert string, config *tls.Config) Builder
- func WithTimeouts(read, readHeader, write, idle time.Duration) Builder
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewBasicAutocertManager ¶
NewBasicAutocertManager creates a autocert manager with sane default values.
Types ¶
type Builder ¶
Builder is a configuration builder function.
func WithHTTP ¶
WithHTTP allows you to create a server listener for HTTP connections. If New is also called with WithHTTPS or WithLetsEncrypt/WithLetsEncryptManager then this listener will function as a redirect listener and redirect traffic to HTTPS.
If used with WithLetsEncrypt/WithLetsEncryptManager you must bind to :80 - as other ports are not supported.
func WithHTTPS ¶
WithHTTPS allows you to create a server listener for HTTPS connections. If you want a custom TLS config, use WithTLS. Otherwise, WithHTTPS will use a sane default tls config.
func WithLetsEncrypt ¶
WithLetsEncrypt allows you to tell the server to use Let's Encrypt with auto-renewal for https certs. This version uses defaults for the autocert Manager & tls config. If you want more control, use WithLetsEncrypt. Bind is not configurable for let's encrypt and will always bind to :443.
If httpChallenge is true, we will create a http -> https redirector that responds to let's encrypt HTTP challenges. This is required for Nginx, CloudFlare, and others because they do not support ALPN challenges. If you want to create a redirector that does not respond to HTTP challenges, and wish to use ALPN instead, you can use WithLetsEncrypt in conjunction with WithHTTP. Otherwise, you don't need to use WithHTTP.
func WithLetsEncryptManager ¶
WithLetsEncryptManager allows you to tell the server to use Let's Encrypt with auto-renewal for https certs. If you'd like to use a default autocert Manager you can get one from NewBasicAutocertManager to provide here. If tls config is nil we will use a default tls config. If not-nil, the GetCertificate and NextProtos values will be replaced by values from the autocert manager's default TLS config, obtained via manager.TLSConfig(). Bind is not configurable for let's encrypt and will always bind to :443.
If httpChallenge is true, we will create a http -> https redirector that responds to let's encrypt HTTP challenges. This is required for Nginx, CloudFlare, and others because they do not support ALPN challenges. If you want to create a redirector that does not respond to HTTP challenges, and wish to use ALPN instead, you can use WithLetsEncryptManager in conjunction with WithHTTP. Otherwise, you don't need to use WithHTTP.
func WithTLS ¶
WithTLS allows you to create a server listener for HTTPS connections with a custom TLS config. If you want a simple HTTPS listener using a sane default TLS config, use WithHTTPS.
func WithTimeouts ¶
WithTimeouts allows you to specify your own listener timeout values. Timeout docs can be found here: https://golang.org/pkg/net/http/
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func New ¶
New returns a new config to be supplied to Start to start the server. Writing to the returned kill chan will gracefully shutdown the server. Returns an error and a nil config if there are conflicting configuration entries.
The most basic way to get started is: New(router, logger, servers.WithLetsEncrypt(true, "domain.com")) This creates a lets encrypt listener on :443, with a redirector on :80 that responds to let's encrypt http challenges.
If WithHTTP is used alongside WithHTTPS/LetsEncrypt/TLS then the bind port (usually :80) will act as a redirector to the SSL port. You can also specify custom timeouts using WithTimeouts.