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/encode | |
parent | b1bec8c8992424b423db3d92101bd5b4989dcf65 (diff) |
caddyfile: Refactor unmarshaling of module tokens
Eliminates a fair amount of repeated code
Diffstat (limited to 'modules/caddyhttp/encode')
-rw-r--r-- | modules/caddyhttp/encode/caddyfile.go | 13 |
1 files changed, 3 insertions, 10 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) |