From 830a0044bec8bee4228c7579a78d00e9e251ed47 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Tue, 21 Jun 2016 22:32:38 -0600 Subject: [PATCH] Updated Writing a Plugin: Server Type (markdown) --- Writing-a-Plugin:-Server-Type.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Writing-a-Plugin:-Server-Type.md b/Writing-a-Plugin:-Server-Type.md index 765d526..4bbe218 100644 --- a/Writing-a-Plugin:-Server-Type.md +++ b/Writing-a-Plugin:-Server-Type.md @@ -51,6 +51,10 @@ 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(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()`.) +You should not store a a list of contexts with your server type; they will be stored with the Instance and are [accessible from Controllers](https://godoc.org/github.com/mholt/caddy#Controller.Context). Keeping references to contexts lying around will prevent them from being garbage collected if the server is stopped later. -(TODO: Expand this guide with more information...) \ No newline at end of file +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. + +For example: the HTTP server keeps a map of site 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, stores the list of middleware, etc -- all the information needed to set up a site. Each directive's action calls the GetConfig function so they can help set up the site properly. By the time `MakeServers()` is called, all it 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: We will expand this guide with more information...) \ No newline at end of file