diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-08-21 10:46:35 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-08-21 10:46:35 -0600 |
commit | c9980fd3671d873a7197a5ac4d6ac9d6b046abb6 (patch) | |
tree | 75c301ab10590fb5f7d5b869a3424b8d46176bbf /modules/caddyhttp/encode/brotli | |
parent | c4159ef76d279d6a84257b24dbe97430af32eb1e (diff) |
Refactor Caddyfile adapter and module registration
Use piles from which to draw config values.
Module values can return their name, so now we can do two-way mapping
from value to name and name to value; whereas before we could only map
name to value. This was problematic with the Caddyfile adapter since
it receives values and needs to know the name to put in the config.
Diffstat (limited to 'modules/caddyhttp/encode/brotli')
-rw-r--r-- | modules/caddyhttp/encode/brotli/brotli.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/caddyhttp/encode/brotli/brotli.go b/modules/caddyhttp/encode/brotli/brotli.go index 0a9f871..cf055aa 100644 --- a/modules/caddyhttp/encode/brotli/brotli.go +++ b/modules/caddyhttp/encode/brotli/brotli.go @@ -19,16 +19,13 @@ import ( "strconv" "github.com/andybalholm/brotli" - "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" "github.com/caddyserver/caddy/v2" + "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode" ) func init() { - caddy.RegisterModule(caddy.Module{ - Name: "http.encoders.brotli", - New: func() interface{} { return new(Brotli) }, - }) + caddy.RegisterModule(Brotli{}) } // Brotli can create brotli encoders. Note that brotli @@ -37,6 +34,14 @@ type Brotli struct { Quality *int `json:"quality,omitempty"` } +// CaddyModule returns the Caddy module information. +func (Brotli) CaddyModule() caddy.ModuleInfo { + return caddy.ModuleInfo{ + Name: "http.encoders.brotli", + New: func() caddy.Module { return new(Brotli) }, + } +} + // UnmarshalCaddyfile sets up the handler from Caddyfile tokens. func (b *Brotli) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { for d.Next() { |