mirror of
https://github.com/caddyserver/caddy.git
synced 2026-01-17 01:30:34 +00:00
filesystem: Globally declared filesystems, fs directive (#5833)
This commit is contained in:
12
context.go
12
context.go
@@ -23,6 +23,8 @@ import (
|
||||
|
||||
"github.com/caddyserver/certmagic"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/caddyserver/caddy/v2/internal/filesystems"
|
||||
)
|
||||
|
||||
// Context is a type which defines the lifetime of modules that
|
||||
@@ -37,6 +39,7 @@ import (
|
||||
// not actually need to do this).
|
||||
type Context struct {
|
||||
context.Context
|
||||
|
||||
moduleInstances map[string][]Module
|
||||
cfg *Config
|
||||
cleanupFuncs []func()
|
||||
@@ -81,6 +84,15 @@ func (ctx *Context) OnCancel(f func()) {
|
||||
ctx.cleanupFuncs = append(ctx.cleanupFuncs, f)
|
||||
}
|
||||
|
||||
// Filesystems returns a ref to the FilesystemMap
|
||||
func (ctx *Context) Filesystems() FileSystems {
|
||||
// if no config is loaded, we use a default filesystemmap, which includes the osfs
|
||||
if ctx.cfg == nil {
|
||||
return &filesystems.FilesystemMap{}
|
||||
}
|
||||
return ctx.cfg.filesystems
|
||||
}
|
||||
|
||||
// LoadModule loads the Caddy module(s) from the specified field of the parent struct
|
||||
// pointer and returns the loaded module(s). The struct pointer and its field name as
|
||||
// a string are necessary so that reflection can be used to read the struct tag on the
|
||||
|
||||
Reference in New Issue
Block a user