0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/config/controller.go
Matthew Holt c7af6725ca Removed Host() and Port() functions from Controller
I don't think they'll be necessary; can get same info from request Host header
2015-04-15 23:17:28 -06:00

48 lines
1.2 KiB
Go

package config
import "github.com/mholt/caddy/middleware"
// controller is a dispenser of tokens and also
// facilitates setup with the server by providing
// access to its configuration. It implements
// the middleware.Controller interface.
type controller struct {
dispenser
parser *parser
pathScope string
}
// newController returns a new controller.
func newController(p *parser) *controller {
return &controller{
dispenser: dispenser{
cursor: -1,
filename: p.filename,
},
parser: p,
}
}
// Startup registers a function to execute when the server starts.
func (c *controller) Startup(fn func() error) {
c.parser.cfg.Startup = append(c.parser.cfg.Startup, fn)
}
// Shutdown registers a function to execute when the server exits.
func (c *controller) Shutdown(fn func() error) {
c.parser.cfg.Shutdown = append(c.parser.cfg.Shutdown, fn)
}
// Root returns the server root file path.
func (c *controller) Root() string {
if c.parser.cfg.Root == "" {
return "."
} else {
return c.parser.cfg.Root
}
}
// Context returns the path scope that the Controller is in.
func (c *controller) Context() middleware.Path {
return middleware.Path(c.pathScope)
}