autotls

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	*autocert.Manager
}

Manager is a wrapper around autocert.Manager that provides automatic management of SSL/TLS certificates. It embeds autocert.Manager to inherit its methods and functionalities, allowing for seamless integration and usage of automatic certificate management in your application.

func New

func New(opts ...Option) *Manager

New creates a new AutoSSL instance with the provided options. It initializes an autocert.Manager with the AcceptTOS prompt. If no cache is provided in the options, it defaults to using a directory cache.

Parameters:

opts - A variadic list of Option functions to configure the autocert.Manager.

Returns:

A pointer to an AutoSSL instance with the configured autocert.Manager.

func (*Manager) Configure

func (m *Manager) Configure(httpSrv *http.Server, httpsSrv *http.Server)

Configure sets up the HTTP and HTTPS servers with the necessary handlers and TLS configurations. It modifies the HTTP server to use the AutoSSL manager's HTTP handler and ensures the HTTPS server has a TLS configuration with at least TLS 1.2. It also sets the GetCertificate function for the HTTPS server's TLS configuration to use the AutoSSL manager's GetCertificate method.

Parameters:

  • httpSrv: A pointer to the HTTP server to be configured.
  • httpsSrv: A pointer to the HTTPS server to be configured.

type Option

type Option func(*autocert.Manager)

Option is a function type that takes a pointer to autocert.Manager as an argument. It is used to configure the autocert.Manager with various options.

func WithCache

func WithCache(cache autocert.Cache) Option

WithCache sets the cache for the autocert.Manager. It takes an autocert.Cache as an argument and returns an Option that configures the autocert.Manager to use the provided cache.

Example usage:

cache := autocert.DirCache("/path/to/cache")
manager := &autocert.Manager{
    Prompt:     autocert.AcceptTOS,
    Cache:      cache,
}
option := WithCache(cache)
option(manager)

Parameters:

  • cache: The autocert.Cache to be used by the autocert.Manager.

func WithHosts

func WithHosts(hosts ...string) Option

WithHosts returns an Option that sets the HostPolicy of the autocert.Manager to whitelist the provided hosts. This ensures that the manager will only respond to requests for the specified hosts.

Parameters:

hosts - A variadic string parameter representing the hostnames to be whitelisted.

Jump to

Keyboard shortcuts

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