diff options
author | Francis Lavoie <lavofr@gmail.com> | 2020-05-11 17:00:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 15:00:35 -0600 |
commit | dc9f4f13fc1cc102c713c69ded295b3fcf685e96 (patch) | |
tree | cbc2bc158947509b222908bbad862ac5581f1cb4 /caddyconfig/httpcaddyfile/directives.go | |
parent | 4c55d26f11329243591d04ca5a52298b38bca9a8 (diff) |
httpcaddyfile: Make global options pluggable (#3265)
* httpcaddyfile: Make global options pluggable
* httpcaddyfile: Add a global options adapt test
* httpcaddyfile: Wrap err
Co-Authored-By: Dave Henderson <dhenderson@gmail.com>
* httpcaddyfile: Revert wrap err
Co-authored-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index ac401e1..1578772 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -120,6 +120,17 @@ func RegisterHandlerDirective(dir string, setupFunc UnmarshalHandlerFunc) { }) } +// 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 RegisterGlobalOption(opt string, setupFunc UnmarshalGlobalFunc) { + if _, ok := registeredGlobalOptions[opt]; ok { + panic("global option " + opt + " already registered") + } + registeredGlobalOptions[opt] = setupFunc +} + // Helper is a type which helps setup a value from // Caddyfile tokens. type Helper struct { @@ -454,6 +465,13 @@ type ( // for you. These are passed to a call to // RegisterHandlerDirective. UnmarshalHandlerFunc func(h Helper) (caddyhttp.MiddlewareHandler, error) + + // 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. + UnmarshalGlobalFunc func(d *caddyfile.Dispenser) (interface{}, error) ) var registeredDirectives = make(map[string]UnmarshalFunc) + +var registeredGlobalOptions = make(map[string]UnmarshalGlobalFunc) |