github.com/caddyserver/caddy/v2/modules/caddyfs
No package summary is available.
Package
Files: 1. Third party imports: 1. Imports from organisation: 0. Tests: 0. Benchmarks: 0.
Types
Filesystems
Filesystems loads caddy.fs modules into the global filesystem map
type Filesystems struct {
Filesystems []*moduleEntry `json:"filesystems"`
defers []func()
}
moduleEntry
This type doesn't have documentation.
type moduleEntry struct {
Key string `json:"name,omitempty"`
FileSystemRaw json.RawMessage `json:"file_system,omitempty" caddy:"namespace=caddy.fs inline_key=backend"`
fileSystem fs.FS
}
Functions
func (*Filesystems) Cleanup
func (f *Filesystems) Cleanup() error {
for _, v := range f.defers {
v()
}
return nil
}
Cognitive complexity: 3
, Cyclomatic complexity: 2
func (*Filesystems) Provision
func (xs *Filesystems) Provision(ctx caddy.Context) error {
// load the filesystem module
for _, f := range xs.Filesystems {
if len(f.FileSystemRaw) > 0 {
mod, err := ctx.LoadModule(f, "FileSystemRaw")
if err != nil {
return fmt.Errorf("loading file system module: %v", err)
}
f.fileSystem = mod.(fs.FS)
}
// register that module
ctx.Logger().Debug("registering fs", zap.String("fs", f.Key))
ctx.Filesystems().Register(f.Key, f.fileSystem)
// remember to unregister the module when we are done
xs.defers = append(xs.defers, func() {
ctx.Logger().Debug("unregistering fs", zap.String("fs", f.Key))
ctx.Filesystems().Unregister(f.Key)
})
}
return nil
}
Cognitive complexity: 8
, Cyclomatic complexity: 4
func (*Filesystems) Start
func (xs *Filesystems) Start() error { return nil }
Cognitive complexity: 0
, Cyclomatic complexity: 1
func (*Filesystems) Stop
func (xs *Filesystems) Stop() error { return nil }
Cognitive complexity: 0
, Cyclomatic complexity: 1
func (*moduleEntry) UnmarshalCaddyfile
func (f *moduleEntry) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
// key required for now
if !d.Args(&f.Key) {
return d.ArgErr()
}
// get the module json
if !d.NextArg() {
return d.ArgErr()
}
name := d.Val()
modID := "caddy.fs." + name
unm, err := caddyfile.UnmarshalModule(d, modID)
if err != nil {
return err
}
fsys, ok := unm.(fs.FS)
if !ok {
return d.Errf("module %s (%T) is not a supported file system implementation (requires fs.FS)", modID, unm)
}
f.FileSystemRaw = caddyconfig.JSONModuleObject(fsys, "backend", name, nil)
}
return nil
}
Cognitive complexity: 10
, Cyclomatic complexity: 6
func (Filesystems) CaddyModule
CaddyModule returns the Caddy module information.
func (Filesystems) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "caddy.filesystems",
New: func() caddy.Module { return new(Filesystems) },
}
}
Cognitive complexity: 2
, Cyclomatic complexity: 1
Private functions
func init
init ()
References: httpcaddyfile.RegisterGlobalOption.
func parseFilesystems
parseFilesystems (d *caddyfile.Dispenser, existingVal any) (any, error)