MCPcopy
hub / github.com/caddyserver/caddy / parseCaddyfile

Function parseCaddyfile

modules/caddyhttp/templates/caddyfile.go:36–81  ·  view source on GitHub ↗

parseCaddyfile sets up the handler from Caddyfile tokens. Syntax: templates [<matcher>] { mime <types...> between <open_delim> <close_delim> root <path> }

(h httpcaddyfile.Helper)

Source from the content-addressed store, hash-verified

34// root <path>
35// }
36func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
37 h.Next() // consume directive name
38 t := new(Templates)
39 for h.NextBlock(0) {
40 switch h.Val() {
41 case "mime":
42 t.MIMETypes = h.RemainingArgs()
43 if len(t.MIMETypes) == 0 {
44 return nil, h.ArgErr()
45 }
46 case "between":
47 t.Delimiters = h.RemainingArgs()
48 if len(t.Delimiters) != 2 {
49 return nil, h.ArgErr()
50 }
51 case "root":
52 if !h.Args(&t.FileRoot) {
53 return nil, h.ArgErr()
54 }
55 case "extensions":
56 if h.NextArg() {
57 return nil, h.ArgErr()
58 }
59 if t.ExtensionsRaw != nil {
60 return nil, h.Err("extensions already specified")
61 }
62 for nesting := h.Nesting(); h.NextBlock(nesting); {
63 extensionModuleName := h.Val()
64 modID := "http.handlers.templates.functions." + extensionModuleName
65 unm, err := caddyfile.UnmarshalModule(h.Dispenser, modID)
66 if err != nil {
67 return nil, err
68 }
69 cf, ok := unm.(CustomFunctions)
70 if !ok {
71 return nil, h.Errf("module %s (%T) does not provide template functions", modID, unm)
72 }
73 if t.ExtensionsRaw == nil {
74 t.ExtensionsRaw = make(caddy.ModuleMap)
75 }
76 t.ExtensionsRaw[extensionModuleName] = caddyconfig.JSON(cf, nil)
77 }
78 }
79 }
80 return t, nil
81}

Callers

nothing calls this directly

Calls 12

UnmarshalModuleFunction · 0.92
JSONFunction · 0.92
NextBlockMethod · 0.80
ValMethod · 0.80
RemainingArgsMethod · 0.80
ArgErrMethod · 0.80
ArgsMethod · 0.80
NextArgMethod · 0.80
ErrMethod · 0.80
NestingMethod · 0.80
ErrfMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected