Documentation
¶
Overview ¶
Package tlscert produces a *tls.Config from either user-supplied cert/key files or an auto-generated self-signed cert covering configured hostnames.
Three modes, checked in order:
- If CertFile and KeyFile are both set, load them directly. The user owns the cert's lifecycle.
- Otherwise, if CacheDir is set, attempt to load `<CacheDir>/tls.crt` + `<CacheDir>/tls.key`. If they don't exist, generate a fresh cert and persist it there so subsequent boots reuse it.
- Otherwise, generate a fresh cert in-memory for this process only.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
CertFile string `env:"TLS_CERT_FILE"` // If set together with KeyFile → load from disk.
KeyFile string `env:"TLS_KEY_FILE"` //
CacheDir string `env:"TLS_CACHE_DIR"` // If set, persist the auto-generated cert here and reuse on restart.
Hostnames []string `env:"TLS_HOSTNAMES" envDefault:"localhost,127.0.0.1,::1"` // SANs for the auto-generated cert.
}
Config selects how the TLS config is built.
The env tags let this struct be populated directly by the env-parsing in config.Specification; consumers that don't care about env vars can ignore them.
Click to show internal directories.
Click to hide internal directories.