mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-26 02:09:47 +08:00
a798e0c951
- Server types no longer need to store their own contexts; they are stored on the caddy.Instance, which means each context will be properly GC'ed when the instance is stopped. Server types should use type assertions to convert from caddy.Context to their concrete context type when they need to use it. - Pass the entire context into httpserver.GetConfig instead of only the Key field. - caddy.NewTestController now requires a server type string so it can create a controller with the proper concrete context associated with that server type. Tests still need more attention so that we can test the proper creation of startup functions, etc.
42 lines
768 B
Go
42 lines
768 B
Go
package root
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/mholt/caddy"
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("root", caddy.Plugin{
|
|
ServerType: "http",
|
|
Action: setupRoot,
|
|
})
|
|
}
|
|
|
|
func setupRoot(c *caddy.Controller) error {
|
|
config := httpserver.GetConfig(c)
|
|
|
|
for c.Next() {
|
|
if !c.NextArg() {
|
|
return c.ArgErr()
|
|
}
|
|
config.Root = c.Val()
|
|
}
|
|
|
|
// Check if root path exists
|
|
_, err := os.Stat(config.Root)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
// Allow this, because the folder might appear later.
|
|
// But make sure the user knows!
|
|
log.Printf("[WARNING] Root path does not exist: %s", config.Root)
|
|
} else {
|
|
return c.Errf("Unable to access root path '%s': %v", config.Root, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|