diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2021-01-05 14:39:30 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2021-01-05 14:39:30 -0700 |
commit | f0216967dca12831b1aac351fc8c4bfcea148697 (patch) | |
tree | 7e444eec3fd296dd45d27a3e36897b37d2ae1b6d /modules/caddyhttp/reverseproxy | |
parent | b1bec8c8992424b423db3d92101bd5b4989dcf65 (diff) |
caddyfile: Refactor unmarshaling of module tokens
Eliminates a fair amount of repeated code
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r-- | modules/caddyhttp/reverseproxy/caddyfile.go | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index 57f425a..895bcbb 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -241,21 +241,14 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.Err("load balancing selection policy already specified") } name := d.Val() - mod, err := caddy.GetModule("http.reverse_proxy.selection_policies." + name) - if err != nil { - return d.Errf("getting load balancing policy module '%s': %v", mod, err) - } - unm, ok := mod.New().(caddyfile.Unmarshaler) - if !ok { - return d.Errf("load balancing policy module '%s' is not a Caddyfile unmarshaler", mod) - } - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) + modID := "http.reverse_proxy.selection_policies." + name + unm, err := caddyfile.UnmarshalModule(d, modID) if err != nil { return err } sel, ok := unm.(Selector) if !ok { - return d.Errf("module %s is not a Selector", mod) + return d.Errf("module %s (%T) is not a reverseproxy.Selector", modID, unm) } if h.LoadBalancing == nil { h.LoadBalancing = new(LoadBalancing) @@ -574,21 +567,14 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.Err("transport already specified") } transportModuleName = d.Val() - mod, err := caddy.GetModule("http.reverse_proxy.transport." + transportModuleName) - if err != nil { - return d.Errf("getting transport module '%s': %v", mod, err) - } - unm, ok := mod.New().(caddyfile.Unmarshaler) - if !ok { - return d.Errf("transport module '%s' is not a Caddyfile unmarshaler", mod) - } - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) + modID := "http.reverse_proxy.transport." + transportModuleName + unm, err := caddyfile.UnmarshalModule(d, modID) if err != nil { return err } rt, ok := unm.(http.RoundTripper) if !ok { - return d.Errf("module %s is not a RoundTripper", mod) + return d.Errf("module %s (%T) is not a RoundTripper", modID, unm) } transport = rt |