Documentation ¶
Index ¶
- func ParseSegmentAsSubroute(h Helper) (caddyhttp.MiddlewareHandler, error)
- func RegisterDirective(dir string, setupFunc UnmarshalFunc)
- func RegisterGlobalOption(opt string, setupFunc UnmarshalGlobalFunc)
- func RegisterHandlerDirective(dir string, setupFunc UnmarshalHandlerFunc)
- type Address
- type ConfigValue
- type Helper
- func (h Helper) Caddyfiles() []string
- func (h Helper) ExtractMatcherSet() (caddy.ModuleMap, error)
- func (h Helper) GroupRoutes(vals []ConfigValue)
- func (h Helper) JSON(val interface{}) json.RawMessage
- func (h Helper) MatcherToken() (caddy.ModuleMap, bool, error)
- func (h Helper) NewBindAddresses(addrs []string) []ConfigValue
- func (h Helper) NewRoute(matcherSet caddy.ModuleMap, handler caddyhttp.MiddlewareHandler) []ConfigValue
- func (h Helper) Option(name string) interface{}
- type ServerType
- type UnmarshalFunc
- type UnmarshalGlobalFunc
- type UnmarshalHandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseSegmentAsSubroute ¶
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 ¶
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.
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 ¶
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 ¶
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.
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 ¶
Caddyfiles returns the list of config files from which tokens in the current server block were loaded.
func (Helper) ExtractMatcherSet ¶
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 ¶
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.
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]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 UnmarshalGlobalFunc ¶
UnmarshalGlobalFunc is a function which can unmarshal Caddyfile tokens into a global option config value using a Helper type. These are passed in a call to RegisterGlobalOption.
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.