Documentation ¶
Index ¶
- Constants
- Variables
- func GetModuleID(instance interface{}) string
- func GetModuleName(instance interface{}) string
- func GoModule() *debug.Module
- func JoinNetworkAddress(network, host, port string) string
- func Listen(network, addr string) (net.Listener, error)
- func ListenPacket(network, addr string) (net.PacketConn, error)
- func Load(r io.Reader) error
- func Modules() []string
- func ParseNetworkAddress(addr string) (network string, addrs []string, err error)
- func RegisterModule(instance Module) error
- func Run(newCfg *Config) error
- func SplitNetworkAddress(a string) (network, host, port string, err error)
- func StartAdmin(initialConfigJSON []byte) error
- func Stop() error
- func StopAdmin() error
- func TrapSignals()
- func Validate(cfg *Config) error
- type AdminConfig
- type AdminRoute
- type AdminRouter
- type App
- type CleanerUpper
- type Config
- type Context
- func (ctx Context) App(name string) (interface{}, error)
- func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{}, error)
- func (ctx Context) LoadModuleInline(moduleNameKey, moduleScope string, raw json.RawMessage) (interface{}, error)
- func (ctx *Context) OnCancel(f func())
- func (ctx Context) Storage() certmagic.Storage
- type CtxKey
- type Duration
- type Module
- type ModuleInfo
- type Provisioner
- type ReplacementFunc
- type Replacer
- type StorageConverter
- type UsagePool
- type Validator
Constants ¶
const ( ExitCodeSuccess = iota ExitCodeFailedStartup ExitCodeForceQuit ExitCodeFailedQuit )
Exit codes. Generally, you should NOT automatically restart the process if the exit code is ExitCodeFailedStartup (1).
Variables ¶
var DefaultAdminConfig = &AdminConfig{ Listen: DefaultAdminListen, }
DefaultAdminConfig is the default configuration for the administration endpoint.
var DefaultAdminListen = "localhost:2019"
DefaultAdminListen is the address for the admin listener, if none is specified at startup.
Functions ¶
func GetModuleID ¶
func GetModuleID(instance interface{}) string
GetModuleID returns a module's ID (the last element of its name) from an instance of its value. If the value is not a module, an empty string will be returned.
func GetModuleName ¶
func GetModuleName(instance interface{}) string
GetModuleName returns a module's name from an instance of its value. If the value is not a module, an empty name will be returned.
func GoModule ¶
GoModule returns the build info of this Caddy build from debug.BuildInfo (requires Go modules). If no version information is available, a non-nil value will still be returned, but with an unknown version.
func JoinNetworkAddress ¶
JoinNetworkAddress combines network, host, and port into a single address string of the form "network/host:port". Port may be a port range. For unix sockets, the network should be "unix" and the path to the socket should be given in the host argument.
func Listen ¶
Listen returns a listener suitable for use in a Caddy module. Always be sure to close listeners when you are done with them.
func ListenPacket ¶
func ListenPacket(network, addr string) (net.PacketConn, error)
ListenPacket returns a net.PacketConn suitable for use in a Caddy module. Always be sure to close the PacketConn when you are done.
func Modules ¶
func Modules() []string
Modules returns the names of all registered modules in ascending lexicographical order.
func ParseNetworkAddress ¶
ParseNetworkAddress parses addr, a string of the form "network/host:port" (with any part optional) into its component parts. Because a port can also be a port range, there may be multiple addresses returned.
func RegisterModule ¶
RegisterModule registers a module by receiving a plain/empty value of the module. For registration to be properly recorded, this should be called in the init phase of runtime. Typically, the module package will do this as a side-effect of being imported. This function returns an error if the module's info is incomplete or invalid, or if the module is already registered.
func SplitNetworkAddress ¶
SplitNetworkAddress splits a into its network, host, and port components. Note that port may be a port range, or omitted for unix sockets.
func StartAdmin ¶
StartAdmin starts Caddy's administration endpoint, bootstrapping it with an optional configuration in the format of JSON bytes. It opens a listener resource. When no longer needed, StopAdmin should be called.
func Stop ¶
func Stop() error
Stop stops running the current configuration. It is the antithesis of Run(). This function will log any errors that occur during the stopping of individual apps and continue to stop the others.
func TrapSignals ¶
func TrapSignals()
TrapSignals create signal/interrupt handlers as best it can for the current OS. This is a rather invasive function to call in a Go program that captures signals already, so in that case it would be better to implement these handlers yourself.
Types ¶
type AdminConfig ¶
type AdminConfig struct {
Listen string `json:"listen,omitempty"`
}
AdminConfig configures the admin endpoint.
type AdminRoute ¶
AdminRoute represents a route for the admin endpoint.
type AdminRouter ¶
type AdminRouter interface {
Routes() []AdminRoute
}
AdminRouter is a type which can return routes for the admin API.
type CleanerUpper ¶
type CleanerUpper interface {
Cleanup() error
}
CleanerUpper is implemented by modules which may have side-effects such as opened files, spawned goroutines, or allocated some sort of non-stack state when they were provisioned. This method should deallocate/cleanup those resources to prevent memory leaks. Cleanup should be fast and efficient. Cleanup should work even if Provision returns an error, to allow cleaning up from partial provisionings.
type Config ¶
type Config struct { Admin *AdminConfig `json:"admin,omitempty"` StorageRaw json.RawMessage `json:"storage,omitempty"` AppsRaw map[string]json.RawMessage `json:"apps,omitempty"` // contains filtered or unexported fields }
Config represents a Caddy configuration.
type Context ¶
Context is a type which defines the lifetime of modules that are loaded and provides access to the parent configuration that spawned the modules which are loaded. It should be used with care and wrapped with derivation functions from the standard context package only if you don't need the Caddy specific features. These contexts are cancelled when the lifetime of the modules loaded from it is over.
Use NewContext() to get a valid value (but most modules will not actually need to do this).
func NewContext ¶
func NewContext(ctx Context) (Context, context.CancelFunc)
NewContext provides a new context derived from the given context ctx. Normally, you will not need to call this function unless you are loading modules which have a different lifespan than the ones for the context the module was provisioned with. Be sure to call the cancel func when the context is to be cleaned up so that modules which are loaded will be properly unloaded. See standard library context package's documentation.
func (Context) App ¶
App returns the configured app named name. If no app with that name is currently configured, a new empty one will be instantiated. (The app module must still be registered.)
func (Context) LoadModule ¶
func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{}, error)
LoadModule decodes rawMsg into a new instance of mod and returns the value. If mod.New() does not return a pointer value, it is converted to one so that it is unmarshaled into the underlying concrete type. If mod.New is nil, an error is returned. If the module implements Validator or Provisioner interfaces, those methods are invoked to ensure the module is fully configured and valid before being used.
func (Context) LoadModuleInline ¶
func (ctx Context) LoadModuleInline(moduleNameKey, moduleScope string, raw json.RawMessage) (interface{}, error)
LoadModuleInline loads a module from a JSON raw message which decodes to a map[string]interface{}, where one of the keys is moduleNameKey and the corresponding value is the module name as a string, which can be found in the given scope.
This allows modules to be decoded into their concrete types and used when their names cannot be the unique key in a map, such as when there are multiple instances in the map or it appears in an array (where there are no custom keys). In other words, the key containing the module name is treated special/separate from all the other keys.
type CtxKey ¶
type CtxKey string
CtxKey is a value type for use with context.WithValue.
const ReplacerCtxKey CtxKey = "replacer"
ReplacerCtxKey is the context key for a replacer.
type Duration ¶
Duration is a JSON-string-unmarshable duration type.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON satisfies json.Unmarshaler.
type Module ¶
type Module interface { // This method indicates the type is a Caddy // module. The returned ModuleInfo must have // both a name and a constructor function. // This method must not have any side-effects. CaddyModule() ModuleInfo }
Module is a type that is used as a Caddy module.
type ModuleInfo ¶
type ModuleInfo struct { // Name is the full name of the module. It // must be unique and properly namespaced. Name string // New returns a pointer to a new, empty // instance of the module's type. The host // module which instantiates this module will // likely type-assert and invoke methods on // the returned value. This function must not // have any side-effects. New func() Module }
ModuleInfo represents a registered Caddy module.
func GetModule ¶
func GetModule(name string) (ModuleInfo, error)
GetModule returns module information from its full name.
func GetModules ¶
func GetModules(scope string) []ModuleInfo
GetModules returns all modules in the given scope/namespace. For example, a scope of "foo" returns modules named "foo.bar", "foo.loo", but not "bar", "foo.bar.loo", etc. An empty scope returns top-level modules, for example "foo" or "bar". Partial scopes are not matched (i.e. scope "foo.ba" does not match name "foo.bar").
Because modules are registered to a map, the returned slice will be sorted to keep it deterministic.
func (ModuleInfo) ID ¶
func (mi ModuleInfo) ID() string
ID returns a module's ID, which is the last element of its name.
func (ModuleInfo) Namespace ¶
func (mi ModuleInfo) Namespace() string
Namespace returns the module's namespace (scope) which is all but the last element of its name. If there is no explicit namespace in the name, the whole name is considered the namespace.
func (ModuleInfo) String ¶
func (mi ModuleInfo) String() string
type Provisioner ¶
Provisioner is implemented by modules which may need to perform some additional "setup" steps immediately after being loaded. Provisioning should be fast (imperceptible running time). If any side-effects result in the execution of this function (e.g. creating global state, any other allocations which require garbage collection, opening files, starting goroutines etc.), be sure to clean up properly by implementing the CleanerUpper interface to avoid leaking resources.
type ReplacementFunc ¶
ReplacementFunc is a function that returns a replacement for the given key along with true if the function is able to service that key (even if the value is blank). If the function does not recognize the key, false should be returned.
type Replacer ¶
type Replacer interface { Set(variable, value string) Delete(variable string) Map(ReplacementFunc) ReplaceAll(input, empty string) string }
Replacer can replace values in strings.
type StorageConverter ¶
StorageConverter is a type that can convert itself to a valid, usable certmagic.Storage value. (The value might be short-lived.) This interface allows us to adapt any CertMagic storage implementation into a consistent API for Caddy configuration.
type UsagePool ¶
type UsagePool struct {
// contains filtered or unexported fields
}
UsagePool is a thread-safe map that pools values based on usage; a LoadOrStore operation increments the usage, and a Delete decrements from the usage. If the usage count reaches 0, the value will be removed from the map. There is no way to overwrite existing keys in the pool without first deleting it as many times as it was stored. Deleting too many times will panic.
An empty UsagePool is NOT safe to use; always call NewUsagePool() to make a new value.
func (*UsagePool) Delete ¶
Delete decrements the usage count for key and removes the value from the underlying map if the usage is 0. It returns true if the usage count reached 0 and the value was deleted. It panics if the usage count drops below 0; always call Delete precisely as many times as LoadOrStore.
func (*UsagePool) LoadOrStore ¶
LoadOrStore puts val in the pool and returns false if key does not already exist; otherwise if the key exists, it loads the existing value, increments the usage for that value, and returns the value along with true.
type Validator ¶
type Validator interface {
Validate() error
}
Validator is implemented by modules which can verify that their configurations are valid. This method will be called after Provision() (if implemented). Validation should always be fast (imperceptible running time) and an error should be returned only if the value's configuration is invalid.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
modules
|
|
caddyhttp/encode
Package encode implements an encoder middleware for Caddy.
|
Package encode implements an encoder middleware for Caddy. |
caddytls/distributedstek
Package distributedstek provides TLS session ticket ephemeral keys (STEKs) in a distributed fashion by utilizing configured storage for locking and key sharing.
|
Package distributedstek provides TLS session ticket ephemeral keys (STEKs) in a distributed fashion by utilizing configured storage for locking and key sharing. |
pkg
|
|