mirror of
https://github.com/caddyserver/caddy.git
synced 2026-05-21 22:36:32 -04:00
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.
This commit is contained in:
@@ -35,10 +35,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterModule(caddy.Module{
|
||||
Name: "http.handlers.encode",
|
||||
New: func() interface{} { return new(Encode) },
|
||||
})
|
||||
caddy.RegisterModule(Encode{})
|
||||
}
|
||||
|
||||
// Encode is a middleware which can encode responses.
|
||||
@@ -50,6 +47,14 @@ type Encode struct {
|
||||
writerPools map[string]*sync.Pool // TODO: these pools do not get reused through config reloads...
|
||||
}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
func (Encode) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
Name: "http.handlers.encode",
|
||||
New: func() caddy.Module { return new(Encode) },
|
||||
}
|
||||
}
|
||||
|
||||
// Provision provisions enc.
|
||||
func (enc *Encode) Provision(ctx caddy.Context) error {
|
||||
for modName, rawMsg := range enc.EncodingsRaw {
|
||||
|
||||
Reference in New Issue
Block a user