tlscert

package
v0.231.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 14 Imported by: 0

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:

  1. If CertFile and KeyFile are both set, load them directly. The user owns the cert's lifecycle.
  2. 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.
  3. Otherwise, generate a fresh cert in-memory for this process only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(cfg Config) (*tls.Config, error)

Load returns a *tls.Config ready for an http.Server.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL