v2.7.6 Latest Latest

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 29 Imported by: 522




This section is empty.


This section is empty.


func ParseSegmentAsSubroute added in v2.1.0

func ParseSegmentAsSubroute(h Helper) (caddyhttp.MiddlewareHandler, error)

ParseSegmentAsSubroute parses the segment such that its subdirectives are themselves treated as directives, from which a subroute is built and returned.

func RegisterDirective

func RegisterDirective(dir string, setupFunc UnmarshalFunc)

RegisterDirective registers a unique directive dir with an associated unmarshaling (setup) function. When directive dir is encountered in a Caddyfile, setupFunc will be called to unmarshal its tokens.

func RegisterGlobalOption added in v2.1.0

func RegisterGlobalOption(opt string, setupFunc UnmarshalGlobalFunc)

RegisterGlobalOption registers a unique global option opt with an associated unmarshaling (setup) function. When the global option opt is encountered in a Caddyfile, setupFunc will be called to unmarshal its tokens.

func RegisterHandlerDirective

func RegisterHandlerDirective(dir string, setupFunc UnmarshalHandlerFunc)

RegisterHandlerDirective is like RegisterDirective, but for directives which specifically output only an HTTP handler. Directives registered with this function will always have an optional matcher token as the first argument.

func WasReplacedPlaceholderShorthand added in v2.5.1

func WasReplacedPlaceholderShorthand(token string) string

WasReplacedPlaceholderShorthand checks if a token string was likely a replaced shorthand of the known Caddyfile placeholder replacement outputs. Useful to prevent some user-defined map output destinations from overlapping with one of the predefined shorthands.


type Address

type Address struct {
	Original, Scheme, Host, Port, Path string

Address represents a site address. It contains the original input value, and the component parts of an address. The component parts may be updated to the correct values as setup proceeds, but the original value should never be changed.

The Host field must be in a normalized form.

func ParseAddress

func ParseAddress(str string) (Address, error)

ParseAddress parses an address string into a structured format with separate scheme, host, port, and path portions, as well as the original input string.

func (Address) Normalize

func (a Address) Normalize() Address

Normalize returns a normalized version of a.

func (Address) String

func (a Address) String() string

String returns a human-readable form of a. It will be a cleaned-up and filled-out URL string.

type App added in v2.4.0

type App struct {
	// The JSON key for the app being configured
	Name string

	// The raw app config as JSON
	Value json.RawMessage

App represents the configuration for a non-standard Caddy app module (e.g. third-party plugin) which was parsed from a global options block.

type ComplexShorthandReplacer added in v2.7.5

type ComplexShorthandReplacer struct {
	// contains filtered or unexported fields

type ConfigValue

type ConfigValue struct {
	// The kind of value this is. As the config is
	// being built, the adapter will look in the
	// "pile" for values belonging to a certain
	// class when it is setting up a certain part
	// of the config. The associated value will be
	// type-asserted and placed accordingly.
	Class string

	// The value to be used when building the config.
	// Generally its type is associated with the
	// name of the Class.
	Value any
	// contains filtered or unexported fields

ConfigValue represents a value to be added to the final configuration, or a value to be consulted when building the final configuration.

type Helper

type Helper struct {
	// State stores intermediate variables during caddyfile adaptation.
	State map[string]any
	// contains filtered or unexported fields

Helper is a type which helps setup a value from Caddyfile tokens.

func (Helper) Caddyfiles

func (h Helper) Caddyfiles() []string

Caddyfiles returns the list of config files from which tokens in the current server block were loaded.

func (Helper) ExtractMatcherSet

func (h Helper) ExtractMatcherSet() (caddy.ModuleMap, error)

ExtractMatcherSet is like MatcherToken, except this is a higher-level method that returns the matcher set described by the matcher token, or nil if there is none, and deletes the matcher token from the dispenser and resets it as if this look-ahead never happened. Useful when wrapping a route (one or more handlers) in a user-defined matcher.

func (Helper) GroupRoutes

func (h Helper) GroupRoutes(vals []ConfigValue)

GroupRoutes adds the routes (caddyhttp.Route type) in vals to the same group, if there is more than one route in vals.

func (Helper) JSON

func (h Helper) JSON(val any) json.RawMessage

JSON converts val into JSON. Any errors are added to warnings.

func (Helper) MatcherToken

func (h Helper) MatcherToken() (caddy.ModuleMap, bool, error)

MatcherToken assumes the next argument token is (possibly) a matcher, and if so, returns the matcher set along with a true value. If the next token is not a matcher, nil and false is returned. Note that a true value may be returned with a nil matcher set if it is a catch-all.

func (Helper) NewBindAddresses

func (h Helper) NewBindAddresses(addrs []string) []ConfigValue

NewBindAddresses returns config values relevant to adding listener bind addresses to the config.

func (Helper) NewRoute

func (h Helper) NewRoute(matcherSet caddy.ModuleMap,
	handler caddyhttp.MiddlewareHandler,
) []ConfigValue

NewRoute returns config values relevant to creating a new HTTP route.

func (Helper) Option

func (h Helper) Option(name string) any

Option gets the option keyed by name.

func (Helper) WithDispenser added in v2.4.0

func (h Helper) WithDispenser(d *caddyfile.Dispenser) Helper

WithDispenser returns a new instance based on d. All others Helper fields are copied, so typically maps are shared with this new instance.

type ServerType

type ServerType struct{}

ServerType can set up a config from an HTTP Caddyfile.

func (ServerType) Setup

func (st ServerType) Setup(
	inputServerBlocks []caddyfile.ServerBlock,
	options map[string]any,
) (*caddy.Config, []caddyconfig.Warning, error)

Setup makes a config from the tokens.

type ShorthandReplacer added in v2.7.5

type ShorthandReplacer struct {
	// contains filtered or unexported fields

func NewShorthandReplacer added in v2.7.5

func NewShorthandReplacer() ShorthandReplacer

func (ShorthandReplacer) ApplyToSegment added in v2.7.5

func (s ShorthandReplacer) ApplyToSegment(segment *caddyfile.Segment)

ApplyToSegment replaces shorthand placeholder to its full placeholder, understandable by Caddy.

type UnmarshalFunc

type UnmarshalFunc func(h Helper) ([]ConfigValue, error)

UnmarshalFunc is a function which can unmarshal Caddyfile tokens into zero or more config values using a Helper type. These are passed in a call to RegisterDirective.

type UnmarshalGlobalFunc added in v2.1.0

type UnmarshalGlobalFunc func(d *caddyfile.Dispenser, existingVal any) (any, error)

UnmarshalGlobalFunc is a function which can unmarshal Caddyfile tokens from a global option. It is passed the tokens to parse and existing value from the previous instance of this global option (if any). It returns the value to associate with this global option.

type UnmarshalHandlerFunc

type UnmarshalHandlerFunc func(h Helper) (caddyhttp.MiddlewareHandler, error)

UnmarshalHandlerFunc is like UnmarshalFunc, except the output of the unmarshaling is an HTTP handler. This function does not need to deal with HTTP request matching which is abstracted away. Since writing HTTP handlers with Caddyfile support is very common, this is a more convenient way to add a handler to the chain since a lot of the details common to HTTP handlers are taken care of for you. These are passed to a call to RegisterHandlerDirective.

Jump to

Keyboard shortcuts

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