mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
Updated Writing a Plugin: Directives (markdown)
parent
8a3783045e
commit
3ded4e940b
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user