From 65fb915f420cfc1e94d99ad4a66c8ed8aa7d2e00 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Mon, 18 Jul 2016 16:41:39 -0600 Subject: [PATCH] Updated Writing a Plugin: Server Type (markdown) --- Writing-a-Plugin:-Server-Type.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Writing-a-Plugin:-Server-Type.md b/Writing-a-Plugin:-Server-Type.md index 908c8bb..349421c 100644 --- a/Writing-a-Plugin:-Server-Type.md +++ b/Writing-a-Plugin:-Server-Type.md @@ -57,15 +57,22 @@ Ultimately, your goal is to make it so that `MakeServers()` returns a list of [c For example: the HTTP server [uses its context type](https://github.com/mholt/caddy/blob/aede4ccbce94bcb67161674e30dd1bfa7296448c/caddyhttp/httpserver/plugin.go#L54-L63) to keep a map of site configs. The package also 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 implement [caddy.Server](https://godoc.org/github.com/mholt/caddy#Server).) -The caddy.Server interface has four methods; two are for TCP, two are for UDP or other: +## Server + +The `caddy.Server` interface considers both TCP and non-TCP servers. It has four methods; two are for TCP, two are for UDP or other: ```go type Server interface { - // Required if using TCP + TCPServer // Required if using TCP + UDPServer // Required if using UDP or other +} + +type TCPServer interface { Listen() (net.Listener, error) Serve(net.Listener) error +} - // Required if using UDP or other +type UDPServer interface { ListenPacket() (net.PacketConn, error) ServePacket(net.PacketConn) error }