Documentation
¶
Overview ¶
Package caddygo provides a Go client for interacting with Caddy's admin API. It allows you to manage domains, TLS certificates, and server configurations programmatically through a clean and intuitive interface.
Index ¶
- type Client
- func (c *Client) AddDomainWithACME(domain, target string, targetPort int, options DomainOptions) error
- func (c *Client) AddDomainWithAutoTLS(domain, target string, targetPort int, options DomainOptions) error
- func (c *Client) AddDomainWithTLS(domain, target string, targetPort int, certificate, privateKey string, ...) error
- func (c *Client) AddDomainWithUpstreams(domain string, targets []UpstreamTarget, lbOptions LoadBalancingOptions, ...) error
- func (c *Client) DeleteDomain(domain string) error
- func (c *Client) Reload() error
- type DomainOptions
- type LoadBalancingOptions
- type UpstreamTarget
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client represents a client for interacting with Caddy's admin API. It provides methods to manage domains, TLS certificates, and server configurations.
func NewClient ¶
NewClient creates a new Caddy API client. If baseURL is empty, it defaults to "http://localhost:2019".
func (*Client) AddDomainWithACME ¶
func (c *Client) AddDomainWithACME(domain, target string, targetPort int, options DomainOptions) error
AddDomainWithACME adds a domain with explicit ACME policy configuration. This approach uses non-on-demand ACME policies for more controlled certificate management.
Parameters:
- domain: The domain name to configure (e.g., "example.com")
- target: The target hostname or IP address
- targetPort: The target port number
- options: Configuration options for security headers, compression, and redirects
Returns an error if the configuration fails.
func (*Client) AddDomainWithAutoTLS ¶
func (c *Client) AddDomainWithAutoTLS(domain, target string, targetPort int, options DomainOptions) error
AddDomainWithAutoTLS adds a domain with automatic TLS configuration. It configures the domain to proxy requests to the specified target and enables automatic certificate management through Let's Encrypt or other ACME providers.
Parameters:
- domain: The domain name to configure (e.g., "example.com")
- target: The target hostname or IP address
- targetPort: The target port number
- options: Configuration options for security headers, compression, and redirects
Returns an error if the configuration fails.
func (*Client) AddDomainWithTLS ¶
func (c *Client) AddDomainWithTLS(domain, target string, targetPort int, certificate, privateKey string, options DomainOptions) error
AddDomainWithTLS adds a domain with a custom TLS certificate. It configures the domain to proxy requests to the specified target using the provided certificate and private key.
Parameters:
- domain: The domain name to configure (e.g., "example.com")
- target: The target hostname or IP address
- targetPort: The target port number
- certificate: PEM-encoded certificate content
- privateKey: PEM-encoded private key content
- options: Configuration options for security headers, compression, and redirects
Returns an error if the configuration fails.
func (*Client) AddDomainWithUpstreams ¶
func (c *Client) AddDomainWithUpstreams(domain string, targets []UpstreamTarget, lbOptions LoadBalancingOptions, options DomainOptions) error
AddDomainWithUpstreams adds a domain with multiple upstream targets and optional load balancing. For a single target with no LB policy, it delegates to AddDomainWithAutoTLS.
func (*Client) DeleteDomain ¶
DeleteDomain removes a domain configuration from Caddy. It removes all routes, TLS policies, and automation rules associated with the domain.
Parameters:
- domain: The domain name to remove (e.g., "example.com")
Returns an error if the deletion fails.
type DomainOptions ¶
type DomainOptions struct {
// EnableSecurityHeaders enables security-related HTTP headers
EnableSecurityHeaders bool
// EnableHSTS enables HTTP Strict Transport Security header
EnableHSTS bool
// FrameOptions sets the X-Frame-Options header value (e.g., "DENY", "SAMEORIGIN")
FrameOptions string
// EnableCompression enables gzip and zstd compression
EnableCompression bool
// RedirectMode sets redirect behavior: "www_to_domain" or "domain_to_www"
RedirectMode string
}
DomainOptions contains configuration options for domain setup. It allows customization of security headers, compression, and redirect behavior.
type LoadBalancingOptions ¶
type LoadBalancingOptions struct {
// Policy is the load balancing algorithm: "round_robin", "first", "least_conn",
// "random", "ip_hash", "uri_hash", "header", "cookie". Empty = Caddy default (random).
Policy string
// HealthCheckPath enables active health checking on this HTTP path (e.g. "/health").
// Empty = no active health checks (passive health checks still apply).
HealthCheckPath string
// HealthCheckIntervalSec is seconds between health check probes. Default: 10.
HealthCheckIntervalSec int
// PassiveFailDurationSec is how long (seconds) to remember a backend's failures.
// After this window the backend is eligible again. 0 = disabled.
PassiveFailDurationSec int
// PassiveMaxFails is consecutive failures within FailDuration before marking unhealthy. 0 = disabled.
PassiveMaxFails int
// PassiveUnhealthyStatus lists HTTP status codes that count as failures (e.g. 502, 503).
PassiveUnhealthyStatus []int
// TryDurationSec is how long Caddy retries other upstreams when one fails. 0 = no retry.
TryDurationSec int
// TryIntervalMs is the pause (milliseconds) between retry attempts. Default: 250.
TryIntervalMs int
}
LoadBalancingOptions configures how traffic is distributed across upstreams.
type UpstreamTarget ¶
UpstreamTarget represents a single backend server.