summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/templates
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/templates')
-rw-r--r--modules/caddyhttp/templates/caddyfile.go37
-rw-r--r--modules/caddyhttp/templates/templates.go13
2 files changed, 27 insertions, 23 deletions
diff --git a/modules/caddyhttp/templates/caddyfile.go b/modules/caddyhttp/templates/caddyfile.go
index d27b8e3..d948da0 100644
--- a/modules/caddyhttp/templates/caddyfile.go
+++ b/modules/caddyhttp/templates/caddyfile.go
@@ -15,11 +15,15 @@
package templates
import (
- "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
-// UnmarshalCaddyfile sets up the handler from Caddyfile tokens. Syntax:
+func init() {
+ httpcaddyfile.RegisterHandlerDirective("templates", parseCaddyfile)
+}
+
+// parseCaddyfile sets up the handler from Caddyfile tokens. Syntax:
//
// templates [<matcher>] {
// mime <types...>
@@ -27,23 +31,24 @@ import (
// root <path>
// }
//
-func (t *Templates) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
- for d.Next() {
- for d.NextBlock() {
- switch d.Val() {
+func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
+ t := new(Templates)
+ for h.Next() {
+ for h.NextBlock() {
+ switch h.Val() {
case "mime":
- t.MIMETypes = d.RemainingArgs()
+ t.MIMETypes = h.RemainingArgs()
if len(t.MIMETypes) == 0 {
- return d.ArgErr()
+ return nil, h.ArgErr()
}
case "between":
- t.Delimiters = d.RemainingArgs()
+ t.Delimiters = h.RemainingArgs()
if len(t.Delimiters) != 2 {
- return d.ArgErr()
+ return nil, h.ArgErr()
}
case "root":
- if !d.Args(&t.IncludeRoot) {
- return d.ArgErr()
+ if !h.Args(&t.IncludeRoot) {
+ return nil, h.ArgErr()
}
}
}
@@ -53,11 +58,5 @@ func (t *Templates) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
t.IncludeRoot = "{http.var.root}"
}
- return nil
+ return t, nil
}
-
-// Bucket returns the HTTP Caddyfile handler bucket number.
-func (t Templates) Bucket() int { return 5 }
-
-// Interface guard
-var _ httpcaddyfile.HandlerDirective = (*Templates)(nil)
diff --git a/modules/caddyhttp/templates/templates.go b/modules/caddyhttp/templates/templates.go
index 442e177..1cd347c 100644
--- a/modules/caddyhttp/templates/templates.go
+++ b/modules/caddyhttp/templates/templates.go
@@ -27,10 +27,7 @@ import (
)
func init() {
- caddy.RegisterModule(caddy.Module{
- Name: "http.handlers.templates",
- New: func() interface{} { return new(Templates) },
- })
+ caddy.RegisterModule(Templates{})
}
// Templates is a middleware which execute response bodies as templates.
@@ -40,6 +37,14 @@ type Templates struct {
Delimiters []string `json:"delimiters,omitempty"`
}
+// CaddyModule returns the Caddy module information.
+func (Templates) CaddyModule() caddy.ModuleInfo {
+ return caddy.ModuleInfo{
+ Name: "http.handlers.templates",
+ New: func() caddy.Module { return new(Templates) },
+ }
+}
+
// Provision provisions t.
func (t *Templates) Provision(ctx caddy.Context) error {
if t.MIMETypes == nil {