Documentation
¶
Overview ¶
Package autotls support Let's Encrypt for a Go server application.
package main
import (
"log"
"github.com/gin-gonic/autotls"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
// Ping handler
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
}
Index ¶
- Variables
- func Run(r http.Handler, domain ...string) error
- func RunWithContext(ctx context.Context, r http.Handler, domain ...string) error
- func RunWithManager(r http.Handler, m *autocert.Manager) error
- func RunWithManagerAndTLSConfig(r http.Handler, m *autocert.Manager, tlsc *tls.Config) error
- func RunWithOptions(ctx context.Context, r http.Handler, options ...Option) error
- type Option
Constants ¶
This section is empty.
Variables ¶
var ReadHeaderTimeout = 3 * time.Second
ReadHeaderTimeout is the maximum duration for reading the headers of the request.
Functions ¶
func Run ¶
Run starts an HTTPS server with automatic Let's Encrypt certificate management and HTTP to HTTPS redirection. The server runs until interrupted and shuts down gracefully.
func RunWithContext ¶ added in v0.0.5
RunWithContext starts an HTTPS server with automatic Let's Encrypt certificate management, HTTP-to-HTTPS redirection, and graceful shutdown. The provided context controls server lifetime.
func RunWithManager ¶
RunWithManager starts an HTTPS server using a custom autocert.Manager for certificate administration. Useful for advanced autocert settings; includes HTTP to HTTPS redirection.
func RunWithManagerAndTLSConfig ¶ added in v0.0.4
RunWithManagerAndTLSConfig starts an HTTPS server using a custom autocert.Manager and custom tls.Config, with HTTP to HTTPS redirection. Allows advanced TLS and certificate settings. r - HTTP handler for HTTPS requests m - autocert.Manager, manages certificate issuance and renewal tlsc - Custom TLS configuration to control various certificate and protocol settings
func RunWithOptions ¶ added in v1.3.0
RunWithOptions serves HTTPS and HTTP ACME challenges on the configured addresses. Non-challenge HTTP requests redirect to HTTPS. Both listeners must start successfully before either server begins serving. The existing Run helpers are unchanged; use this entry point to restrict the listening interfaces.
ACME validation must still reach public port 80 (HTTP-01) or 443 (TLS-ALPN-01), even when a proxy forwards those ports to different local listening ports. Redirects target the standard public HTTPS port, not the local HTTPS listener port. Options are applied in order; the last value for each setting wins. Nil options are rejected. Non-empty WithDomains and a non-nil WithManager cannot be combined. On context cancellation, both servers have up to five seconds to shut down; successful shutdown returns nil. An already-canceled context returns its error.
Types ¶
type Option ¶ added in v1.3.0
type Option func(*serverConfig)
Option configures RunWithOptions. Use the With functions to create options.
func WithDomains ¶ added in v1.3.0
WithDomains restricts certificate issuance when no custom manager is supplied. An empty list allows any domain, which is not recommended. The names are copied when the option is created. Do not combine a non-empty list with a non-nil WithManager.
func WithHTTPAddr ¶ added in v1.3.0
WithHTTPAddr sets the HTTP challenge and redirect address. Empty means ":80".
func WithHTTPSAddr ¶ added in v1.3.0
WithHTTPSAddr sets the HTTPS application address. Empty means ":443".
func WithManager ¶ added in v1.3.0
WithManager supplies certificate management and its host policy. Nil selects the default manager. If its Cache is nil, RunWithOptions sets the default disk cache before use. Do not modify or start using the manager concurrently during setup. Do not combine a non-nil manager with non-empty WithDomains.
func WithTLSConfig ¶ added in v1.3.0
WithTLSConfig supplies TLS settings. Nil selects the manager's default TLS configuration. A non-nil configuration is cloned before setting GetCertificate and NextProtos from the certificate manager.
Directories
¶
| Path | Synopsis |
|---|---|
|
_example
|
|
|
custom-ports
command
Example non-standard local ports behind public ACME port forwarding.
|
Example non-standard local ports behind public ACME port forwarding. |
|
custom-tls
command
Example custom TLS policy using autotls's existing configuration helper.
|
Example custom TLS policy using autotls's existing configuration helper. |
|
example1
command
|
|
|
example2
command
|
|
|
example3
command
|