diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/encode/caddyfile.go | 13 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/caddyfile.go | 26 | ||||
-rw-r--r-- | modules/caddytls/acmeissuer.go | 13 | ||||
-rw-r--r-- | modules/logging/filterencoder.go | 30 |
4 files changed, 20 insertions, 62 deletions
diff --git a/modules/caddyhttp/encode/caddyfile.go b/modules/caddyhttp/encode/caddyfile.go index 9d9646c..2f11ca0 100644 --- a/modules/caddyhttp/encode/caddyfile.go +++ b/modules/caddyhttp/encode/caddyfile.go @@ -64,21 +64,14 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { for d.NextBlock(0) { name := d.Val() - mod, err := caddy.GetModule("http.encoders." + name) - if err != nil { - return fmt.Errorf("getting encoder module '%s': %v", name, err) - } - unm, ok := mod.New().(caddyfile.Unmarshaler) - if !ok { - return fmt.Errorf("encoder module '%s' is not a Caddyfile unmarshaler", mod) - } - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) + modID := "http.encoders." + name + unm, err := caddyfile.UnmarshalModule(d, modID) if err != nil { return err } encoding, ok := unm.(Encoding) if !ok { - return fmt.Errorf("module %s is not an HTTP encoding", mod) + return fmt.Errorf("module %s is not an HTTP encoding; is %T", modID, unm) } if enc.EncodingsRaw == nil { enc.EncodingsRaw = make(caddy.ModuleMap) 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 diff --git a/modules/caddytls/acmeissuer.go b/modules/caddytls/acmeissuer.go index df071c4..43e758f 100644 --- a/modules/caddytls/acmeissuer.go +++ b/modules/caddytls/acmeissuer.go @@ -354,18 +354,11 @@ func (iss *ACMEIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if iss.Challenges.DNS == nil { iss.Challenges.DNS = new(DNSChallengeConfig) } - dnsProvModule, err := caddy.GetModule("dns.providers." + provName) + unm, err := caddyfile.UnmarshalModule(d, "dns.providers."+provName) if err != nil { - return d.Errf("getting DNS provider module named '%s': %v", provName, err) + return err } - dnsProvModuleInstance := dnsProvModule.New() - if unm, ok := dnsProvModuleInstance.(caddyfile.Unmarshaler); ok { - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) - if err != nil { - return err - } - } - iss.Challenges.DNS.ProviderRaw = caddyconfig.JSONModuleObject(dnsProvModuleInstance, "name", provName, nil) + iss.Challenges.DNS.ProviderRaw = caddyconfig.JSONModuleObject(unm, "name", provName, nil) case "resolvers": if iss.Challenges == nil { diff --git a/modules/logging/filterencoder.go b/modules/logging/filterencoder.go index d1c335f..cdb552d 100644 --- a/modules/logging/filterencoder.go +++ b/modules/logging/filterencoder.go @@ -115,21 +115,14 @@ func (fe *FilterEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.ArgErr() } moduleName := d.Val() - mod, err := caddy.GetModule("caddy.logging.encoders." + moduleName) - if err != nil { - return d.Errf("getting log encoder module named '%s': %v", moduleName, err) - } - unm, ok := mod.New().(caddyfile.Unmarshaler) - if !ok { - return d.Errf("log encoder module '%s' is not a Caddyfile unmarshaler", mod) - } - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) + moduleID := "caddy.logging.encoders." + moduleName + unm, err := caddyfile.UnmarshalModule(d, moduleID) if err != nil { return err } enc, ok := unm.(zapcore.Encoder) if !ok { - return d.Errf("module %s is not a zapcore.Encoder", mod) + return d.Errf("module %s (%T) is not a zapcore.Encoder", moduleID, unm) } fe.WrappedRaw = caddyconfig.JSONModuleObject(enc, "format", moduleName, nil) @@ -140,26 +133,19 @@ func (fe *FilterEncoder) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.ArgErr() } filterName := d.Val() - mod, err := caddy.GetModule("caddy.logging.encoders.filter." + filterName) - if err != nil { - return d.Errf("getting log filter module named '%s': %v", filterName, err) - } - unm, ok := mod.New().(caddyfile.Unmarshaler) - if !ok { - return d.Errf("log encoder module '%s' is not a Caddyfile unmarshaler", mod) - } - err = unm.UnmarshalCaddyfile(d.NewFromNextSegment()) + moduleID := "caddy.logging.encoders.filter." + filterName + unm, err := caddyfile.UnmarshalModule(d, moduleID) if err != nil { return err } - f, ok := unm.(LogFieldFilter) + filter, ok := unm.(LogFieldFilter) if !ok { - return d.Errf("module %s is not a LogFieldFilter", mod) + return d.Errf("module %s (%T) is not a logging.LogFieldFilter", moduleID, unm) } if fe.FieldsRaw == nil { fe.FieldsRaw = make(map[string]json.RawMessage) } - fe.FieldsRaw[field] = caddyconfig.JSONModuleObject(f, "filter", filterName, nil) + fe.FieldsRaw[field] = caddyconfig.JSONModuleObject(filter, "filter", filterName, nil) } default: |