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

Method UnmarshalCaddyfile

modules/caddyhttp/fileserver/caddyfile.go:67–203  ·  view source on GitHub ↗

UnmarshalCaddyfile parses the file_server directive. It enables the static file server and configures it with this syntax: file_server [<matcher>] [browse] { fs <filesystem> root <path> hide <files...> index <files...> browse [<t

(d *caddyfile.Dispenser)

Source from the content-addressed store, hash-verified

65// The FinalizeUnmarshalCaddyfile method should be called after this
66// to finalize setup of hidden Caddyfiles.
67func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
68 d.Next() // consume directive name
69
70 args := d.RemainingArgs()
71 switch len(args) {
72 case 0:
73 case 1:
74 if args[0] != "browse" {
75 return d.ArgErr()
76 }
77 fsrv.Browse = new(Browse)
78 default:
79 return d.ArgErr()
80 }
81
82 for nesting := d.Nesting(); d.NextBlock(nesting); {
83 switch d.Val() {
84 case "fs":
85 if !d.NextArg() {
86 return d.ArgErr()
87 }
88 if fsrv.FileSystem != "" {
89 return d.Err("file system already specified")
90 }
91 fsrv.FileSystem = d.Val()
92
93 case "hide":
94 fsrv.Hide = d.RemainingArgs()
95 if len(fsrv.Hide) == 0 {
96 return d.ArgErr()
97 }
98
99 case "index":
100 fsrv.IndexNames = d.RemainingArgs()
101 if len(fsrv.IndexNames) == 0 {
102 return d.ArgErr()
103 }
104
105 case "root":
106 if !d.Args(&fsrv.Root) {
107 return d.ArgErr()
108 }
109
110 case "browse":
111 if fsrv.Browse != nil {
112 return d.Err("browsing is already configured")
113 }
114 fsrv.Browse = new(Browse)
115 d.Args(&fsrv.Browse.TemplateFile)
116 for nesting := d.Nesting(); d.NextBlock(nesting); {
117 switch d.Val() {
118 case "reveal_symlinks":
119 if fsrv.Browse.RevealSymlinks {
120 return d.Err("Symlinks path reveal is already enabled")
121 }
122 fsrv.Browse.RevealSymlinks = true
123 case "sort":
124 for d.NextArg() {

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected