mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-22 09:39:58 +08: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:
@ -15,22 +15,27 @@
|
||||
package caddyzstd
|
||||
|
||||
import (
|
||||
"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"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.RegisterModule(caddy.Module{
|
||||
Name: "http.encoders.zstd",
|
||||
New: func() interface{} { return new(Zstd) },
|
||||
})
|
||||
caddy.RegisterModule(Zstd{})
|
||||
}
|
||||
|
||||
// Zstd can create Zstandard encoders.
|
||||
type Zstd struct{}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
func (Zstd) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
Name: "http.encoders.zstd",
|
||||
New: func() caddy.Module { return new(Zstd) },
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalCaddyfile sets up the handler from Caddyfile tokens.
|
||||
func (z *Zstd) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user