httpcaddyfile

package
v2.0.0-beta.16 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: Apache-2.0 Imports: 16 Imported by: 637

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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.

Types

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) Key

func (a Address) Key() string

Key returns a string form of a, much like String() does, but this method doesn't add anything default that wasn't in the original.

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 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 interface{}
	// 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 {
	*caddyfile.Dispenser
	// State stores intermediate variables during caddyfile adaptation.
	State map[string]interface{}
	// 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 interface{}) 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) interface{}

Option gets the option keyed by name.

type ServerType

type ServerType struct {
}

ServerType can set up a config from an HTTP Caddyfile.

func (ServerType) Setup

func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
	options map[string]interface{}) (*caddy.Config, []caddyconfig.Warning, error)

Setup makes a config from the tokens.

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 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