mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-29 23:25:50 +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:
@ -36,10 +36,7 @@ import (
|
||||
func init() {
|
||||
weakrand.Seed(time.Now().UnixNano())
|
||||
|
||||
caddy.RegisterModule(caddy.Module{
|
||||
Name: "http.handlers.file_server",
|
||||
New: func() interface{} { return new(FileServer) },
|
||||
})
|
||||
caddy.RegisterModule(FileServer{})
|
||||
}
|
||||
|
||||
// FileServer implements a static file server responder for Caddy.
|
||||
@ -50,6 +47,14 @@ type FileServer struct {
|
||||
Browse *Browse `json:"browse,omitempty"`
|
||||
}
|
||||
|
||||
// CaddyModule returns the Caddy module information.
|
||||
func (FileServer) CaddyModule() caddy.ModuleInfo {
|
||||
return caddy.ModuleInfo{
|
||||
Name: "http.handlers.file_server",
|
||||
New: func() caddy.Module { return new(FileServer) },
|
||||
}
|
||||
}
|
||||
|
||||
// Provision sets up the static files responder.
|
||||
func (fsrv *FileServer) Provision(ctx caddy.Context) error {
|
||||
if fsrv.IndexNames == nil {
|
||||
|
Reference in New Issue
Block a user