GetConfig now takes a Controller, not just a key string

Matt Holt 2016-06-20 12:06:44 -06:00
parent 1f8aee2ff9
commit f863d58fa7

@ -51,6 +51,6 @@ Caddy tries to avoid as much global state as possible. When Caddy loads, parses,
Each time Caddy goes through this startup phase, it will create a new caddy.Instance and Caddy will ask your server type for a new [caddy.Context](https://godoc.org/github.com/mholt/caddy#Context) value so that it can execute your server's directives without sharing global state. Read the godoc for caddy.Context for more information.
Ultimately, your goal is to make it so that `MakeServers()` returns a list of servers that Caddy can use. How you do that is entirely up to you. The HTTP server keeps a map of configs in its context and has an exported function, `GetConfig(key string)` that gets a config for a certain site, designated by the key that is passed in. The config, in turn, store the list of middleware, etc -- all the information needed to set up a site. Each directive's action calls that function because each directive is passed the key. Then all `MakeServers()` has to do is combine those site configs into server instances and return them. (Server instances are types on which you can call `Listen()` and `Serve()`.)
Ultimately, your goal is to make it so that `MakeServers()` returns a list of servers that Caddy can use. How you do that is entirely up to you. The HTTP server keeps a map of configs in its context and has an exported function, `GetConfig(c Controller)` that gets a config for a certain site, designated by the [caddy.Controller](https://godoc.org/github.com/mholt/caddy#Controller) that is passed in. The config, in turn, store the list of middleware, etc -- all the information needed to set up a site. Each directive's action calls that function because each directive is passed a Controller. Then all `MakeServers()` has to do is combine those site configs into server instances and return them. (Server instances are types on which you can call `Listen()` and `Serve()`.)
(TODO: Expand this guide with more information...)