caddy

package module
v0.0.0-...-2546b48 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

README

go.destructure.dev/caddy

A Caddy API client for Go

Documentation

Index

Constants

View Source
const DefaultServerAddr = "http://localhost:2019"

DefaultServerAddr is the default address for a Caddy API server.

Variables

This section is empty.

Functions

func MarshalApps

func MarshalApps(apps AppMap) (map[string]json.RawMessage, error)

MarshalApps marshals a map of app modules to raw JSON messages.

func RegisterModule

func RegisterModule(module Module)

RegisterModule adds a module to the registry by it's ID. Registering a module makes it available for lookup when unmarshalling config.

Types

type ActiveHealthCheck

type ActiveHealthCheck struct {
	ID       string        `json:"@id,omitempty"`
	URI      string        `json:"uri,omitempty"`
	Interval time.Duration `json:"interval,omitempty"`
	Timeout  time.Duration `json:"timeout,omitempty"`
}

type AdminConfig

type AdminConfig struct {
	ID       string `json:"@id,omitempty"`
	Disabled bool   `json:"disabled"`
	Listen   string `json:"listen,omitempty"`
}

AdminConfig configures Caddy's API endpoint, which is used to manage Caddy while it is running.

type AppMap

type AppMap map[string]Module

AppMap is a map of app names to app modules.

func UnmarshalApps

func UnmarshalApps(rawApps map[string]json.RawMessage) (AppMap, error)

UnmarshalApps unmarshals a map of app modules.

type AutoHTTPS

type AutoHTTPS struct {
	ID      string `json:"@id,omitempty"`
	Disable bool   `json:"disable"`
}

AutoHTTPS configures or disables automatic HTTPS within a server.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides an API client for the Caddy server.

func NewClient

func NewClient(address string) *Client

NewClient creates a new Caddy API client.

func NewSocketClient

func NewSocketClient(sockAddress string) *Client

NewSocketClient creates a new Caddy API client using a unix socket.

func (*Client) DeleteConfig

func (c *Client) DeleteConfig(ctx context.Context, path string) error

DeleteConfig removes Caddy's configuration at the named path.

func (*Client) GetConfig

func (c *Client) GetConfig(ctx context.Context) (*Config, error)

Exports Caddy's current configuration.

func (*Client) GetConfigByID

func (c *Client) GetConfigByID(ctx context.Context, id string, v any) error

Exports Caddy's current configuration with the given ID. The configuration will be unmarshalled into v.

func (*Client) GetConfigByPath

func (c *Client) GetConfigByPath(ctx context.Context, path string, v any) error

Exports Caddy's current configuration at the named path. The configuration will be unmarshalled into v.

func (*Client) Load

func (c *Client) Load(ctx context.Context, cfg *Config) error

Load sets Caddy's configuration, overriding any previous configuration.

func (*Client) PatchConfig

func (c *Client) PatchConfig(ctx context.Context, path string, cfg any) error

PatchConfig hanges Caddy's configuration at the named path using PATCH semantics.

func (*Client) PostConfig

func (c *Client) PostConfig(ctx context.Context, path string, cfg any) error

PostConfig changes Caddy's configuration at the named path using POST semantics.

func (*Client) PutConfig

func (c *Client) PutConfig(ctx context.Context, path string, cfg any) error

PutConfig hanges Caddy's configuration at the named path using PUT semantics.

type Config

type Config struct {
	Admin      *AdminConfig               `json:"admin,omitempty"`
	Logging    *Logging                   `json:"logging,omitempty"`
	Storage    Module                     `json:"-"`
	StorageRaw json.RawMessage            `json:"storage,omitempty"`
	Apps       map[string]Module          `json:"-"`
	AppsRaw    map[string]json.RawMessage `json:"apps,omitempty"`
}

Config defines the Caddy configuration structure.

func (Config) MarshalJSON

func (c Config) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Config) UnmarshalJSON

func (c *Config) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements json.Unmarshaler.

type FileStorage

type FileStorage struct {
	Storage
	ID   string `json:"@id,omitempty"`
	Root string `json:"root,omitempty"`
}

FileStorage configures a local filesystem for certificate storage.

func NewFileStorage

func NewFileStorage(root string) FileStorage

func (FileStorage) CaddyModule

func (s FileStorage) CaddyModule() ModuleInfo

CaddyModule implements Module.

type HTTP

type HTTP struct {
	ID            string            `json:"@id,omitempty"`
	HTTPPort      int               `json:"http_port,omitempty"`
	HTTPSPort     int               `json:"https_port,omitempty"`
	GracePeriod   time.Duration     `json:"grace_period,omitempty"`
	ShutdownDelay time.Duration     `json:"shutdown_delay,omitempty"`
	Servers       map[string]Server `json:"servers,omitempty"`
}

The HTTP app provides a robust, production-ready HTTP server.

func (HTTP) CaddyModule

func (h HTTP) CaddyModule() ModuleInfo

CaddyModule implements Module.

type Handler

type Handler struct {
	ID      string `json:"@id,omitempty"`
	Handler string `json:"handler"`
}

Handler is a middleware which handles requests.

type HealthChecks

type HealthChecks struct {
	ID     string             `json:"@id,omitempty"`
	Active *ActiveHealthCheck `json:"active,omitempty"`
}

type Logging

type Logging struct {
	ID string `json:"@id,omitempty"`
}

Logging configures logging within Caddy.

type MatcherSet

type MatcherSet struct {
	ID   string   `json:"@id,omitempty"`
	Host []string `json:"host,omitempty"`
	Path []string `json:"path,omitempty"`
}

MatcherSet is used to qualify a route for a request.

type Module

type Module interface {
	CaddyModule() ModuleInfo
}

Module provides configuration for a Caddy module.

func UnmarshalHandler

func UnmarshalHandler(buf []byte) (Module, error)

UnmarshalHandler unmarshals a handler module.

func UnmarshalStorage

func UnmarshalStorage(buf []byte) (Module, error)

UnmarshalStorage unmarshals a storage module.

type ModuleInfo

type ModuleInfo struct {
	// ID is a unique, namespaced identifier for the module.
	// Caddy IDs are dot separated and use snake_case by convention.
	// For example, `caddy.storage.file_system` is a module with the
	// name "file_system" in the namespace "caddy.storage".
	ID string

	// New returns a pointer to a new, empty instance of the module's type.
	New func() Module
}

ModuleInfo describes a Caddy module.

func GetModule

func GetModule(id string) (ModuleInfo, error)

GetModule returns module info for the given ID, if found.

func (ModuleInfo) Name

func (m ModuleInfo) Name() string

Name returns the name of the module.

type ReverseProxy

type ReverseProxy struct {
	Handler
	Upstreams      []Upstream    `json:"upstreams,omitempty"`
	HealthChecks   *HealthChecks `json:"health_checks,omitempty"`
	TrustedProxies []string      `json:"trusted_proxies,omitempty"`
}

ReverseProxy configures a highly configurable and production-ready reverse proxy.

func NewReverseProxy

func NewReverseProxy() ReverseProxy

func (ReverseProxy) CaddyModule

func (s ReverseProxy) CaddyModule() ModuleInfo

CaddyModule implements Module.

type Route

type Route struct {
	ID        string            `json:"@id,omitempty"`
	Group     string            `json:"group,omitempty"`
	Handle    []Module          `json:"-"`
	HandleRaw []json.RawMessage `json:"handle"`
	Match     []MatcherSet      `json:"match"`
}

Route consists of a set of rules for matching HTTP requests, a list of handlers to execute, and optional flow control parameters which customize the handling of HTTP requests in a highly flexible and performant manner.

func (Route) MarshalJSON

func (r Route) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Route) UnmarshalJSON

func (r *Route) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Server

type Server struct {
	ID                string        `json:"@id,omitempty"`
	Listen            []string      `json:"listen"`
	ReadTimeout       time.Duration `json:"read_timeout,omitempty"`
	ReadHeaderTimeout time.Duration `json:"read_header_timeout,omitempty"`
	WriteTimeout      time.Duration `json:"write_timeout,omitempty"`
	IdleTimeout       time.Duration `json:"idle_timeout,omitempty"`
	KeepAliveInterval time.Duration `json:"keepalive_interval,omitempty"`
	MaxHeaderBytes    int           `json:"max_header_bytes,omitempty"`
	Routes            []Route       `json:"routes,omitempty"`
	AutoHTTPS         *AutoHTTPS    `json:"automatic_https,omitempty"`
}

Server describes an HTTP server.

type Storage

type Storage struct {
	ID     string `json:"@id,omitempty"`
	Module string `json:"module"`
}

Storage defines how/where Caddy stores assets (such as TLS certificates).

type TLS

type TLS struct {
	ID string `json:"@id,omitempty"`
}

TLS configures TLS facilities including certificate loading and management, client auth, and more.

func (TLS) CaddyModule

func (t TLS) CaddyModule() ModuleInfo

CaddyModule implements Module.

type Upstream

type Upstream struct {
	ID          string `json:"@id,omitempty"`
	Dial        string `json:"dial"`
	MaxRequests int    `json:"max_requests,omitempty"`
}

Jump to

Keyboard shortcuts

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