From 3ded4e940be9e3a4dcd52292edd80774e44c3726 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Mon, 18 Jul 2016 15:55:42 -0600 Subject: [PATCH] Updated Writing a Plugin: Directives (markdown) --- Writing-a-Plugin:-Directives.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Writing-a-Plugin:-Directives.md b/Writing-a-Plugin:-Directives.md index 57bbb6d..8a77e7d 100644 --- a/Writing-a-Plugin:-Directives.md +++ b/Writing-a-Plugin:-Directives.md @@ -31,7 +31,7 @@ The name of your directive plugin is also the name of the directive. It must be Most directives apply only to a specific type of server. For example, directives for the `"http"` server type such as `gzip` and `fastcgi` configure and inject a middleware handler. These kinds of plugins typically need to import the package of the relevant server type. -Some directives don't pertain to a specific type of server. For example, `tls` is a directive that any server type can use to take advantage of Caddy's powerful TLS capabilities, and `startup` and `shutdown` run commands when a server starts/stops, no matter what type of server it is. In that case, the `ServerType` field can be left empty. In order to be used, server types must be coded to support these kinds of directives. +Some directives don't pertain to a specific type of server. For example, `tls` is a directive that any server type can use to take advantage of Caddy's powerful TLS capabilities, and `startup` and `shutdown` run commands when a server starts/stops, no matter what type of server it is. In that case, the `ServerType` field can be left empty. In order to use these kinds of directives, server types must be coded to support them specifically. ### Action (The "Setup Function") @@ -61,11 +61,11 @@ gizmo foobar We can get the value of the first argument ("foobar") like so: ```go -for c.Next() { - if !c.NextArg() { - return c.ArgErr() - } - value := c.Val() +for c.Next() { // skip the directive name + if !c.NextArg() { // expect at least one value + return c.ArgErr() // otherwise it's an error + } + value := c.Val() // use the value } ```