Add Name function to filesystem to reflect its own name
This commit is contained in:
parent
3a6281295c
commit
ea98205bd6
@ -371,6 +371,7 @@ func (a *api) start() error {
|
||||
})
|
||||
|
||||
diskfs, err := fs.NewDiskFilesystem(fs.DiskConfig{
|
||||
Name: "disk",
|
||||
Dir: cfg.Storage.Disk.Dir,
|
||||
Size: cfg.Storage.Disk.Size * 1024 * 1024,
|
||||
Logger: a.log.logger.core.WithComponent("FS"),
|
||||
@ -399,6 +400,7 @@ func (a *api) start() error {
|
||||
|
||||
if a.memfs == nil {
|
||||
memfs := fs.NewMemFilesystem(fs.MemConfig{
|
||||
Name: "mem",
|
||||
Base: baseMemFS.String(),
|
||||
Size: cfg.Storage.Memory.Size * 1024 * 1024,
|
||||
Purge: cfg.Storage.Memory.Purge,
|
||||
@ -429,6 +431,7 @@ func (a *api) start() error {
|
||||
}
|
||||
|
||||
s3fs, err := fs.NewS3Filesystem(fs.S3Config{
|
||||
Name: s3.Name,
|
||||
Base: baseS3FS.String(),
|
||||
Endpoint: s3.Endpoint,
|
||||
AccessKeyID: s3.AccessKeyID,
|
||||
@ -524,10 +527,20 @@ func (a *api) start() error {
|
||||
a.replacer.RegisterTemplate("srt", template)
|
||||
}
|
||||
|
||||
filesystems := []fs.Filesystem{
|
||||
a.diskfs,
|
||||
a.memfs,
|
||||
}
|
||||
|
||||
for _, fs := range a.s3fs {
|
||||
filesystems = append(filesystems, fs)
|
||||
}
|
||||
|
||||
restream, err := restream.New(restream.Config{
|
||||
ID: cfg.ID,
|
||||
Name: cfg.Name,
|
||||
Store: store,
|
||||
Filesystems: filesystems,
|
||||
DiskFS: a.diskfs,
|
||||
MemFS: a.memfs,
|
||||
Replace: a.replacer,
|
||||
@ -841,9 +854,9 @@ func (a *api) start() error {
|
||||
|
||||
a.log.logger.main = a.log.logger.core.WithComponent(logcontext).WithField("address", cfg.Address)
|
||||
|
||||
filesystems := []httpfs.FS{
|
||||
httpfilesystems := []httpfs.FS{
|
||||
{
|
||||
Name: "disk",
|
||||
Name: a.diskfs.Name(),
|
||||
Mountpoint: "",
|
||||
AllowWrite: false,
|
||||
EnableAuth: false,
|
||||
@ -852,11 +865,11 @@ func (a *api) start() error {
|
||||
DefaultFile: "index.html",
|
||||
DefaultContentType: "text/html",
|
||||
Gzip: true,
|
||||
Filesystem: diskfs,
|
||||
Filesystem: a.diskfs,
|
||||
Cache: a.cache,
|
||||
},
|
||||
{
|
||||
Name: "mem",
|
||||
Name: a.memfs.Name(),
|
||||
Mountpoint: "/memfs",
|
||||
AllowWrite: true,
|
||||
EnableAuth: cfg.Storage.Memory.Auth.Enable,
|
||||
@ -871,7 +884,7 @@ func (a *api) start() error {
|
||||
}
|
||||
|
||||
for _, s3 := range cfg.Storage.S3 {
|
||||
filesystems = append(filesystems, httpfs.FS{
|
||||
httpfilesystems = append(httpfilesystems, httpfs.FS{
|
||||
Name: s3.Name,
|
||||
Mountpoint: s3.Mountpoint,
|
||||
AllowWrite: true,
|
||||
@ -893,7 +906,7 @@ func (a *api) start() error {
|
||||
Metrics: a.metrics,
|
||||
Prometheus: a.prom,
|
||||
MimeTypesFile: cfg.Storage.MimeTypes,
|
||||
Filesystems: filesystems,
|
||||
Filesystems: httpfilesystems,
|
||||
IPLimiter: iplimiter,
|
||||
Profiling: cfg.Debug.Profiling,
|
||||
Cors: http.CorsConfig{
|
||||
|
||||
@ -15,6 +15,9 @@ import (
|
||||
// DiskConfig is the config required to create a new disk
|
||||
// filesystem.
|
||||
type DiskConfig struct {
|
||||
// Namee is the name of the filesystem
|
||||
Name string
|
||||
|
||||
// Dir is the path to the directory to observe
|
||||
Dir string
|
||||
|
||||
@ -109,7 +112,8 @@ func (f *diskFile) Read(p []byte) (int, error) {
|
||||
|
||||
// diskFilesystem implements the Filesystem interface
|
||||
type diskFilesystem struct {
|
||||
dir string
|
||||
name string
|
||||
dir string
|
||||
|
||||
// Max. size of the filesystem in bytes as
|
||||
// given by the config
|
||||
@ -127,6 +131,7 @@ type diskFilesystem struct {
|
||||
// that implements the Filesystem interface
|
||||
func NewDiskFilesystem(config DiskConfig) (Filesystem, error) {
|
||||
fs := &diskFilesystem{
|
||||
name: config.Name,
|
||||
maxSize: config.Size,
|
||||
logger: config.Logger,
|
||||
}
|
||||
@ -144,6 +149,10 @@ func NewDiskFilesystem(config DiskConfig) (Filesystem, error) {
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
func (fs *diskFilesystem) Name() string {
|
||||
return fs.name
|
||||
}
|
||||
|
||||
func (fs *diskFilesystem) Base() string {
|
||||
return fs.dir
|
||||
}
|
||||
|
||||
@ -20,8 +20,11 @@ func (d *dummyFile) Close() error { return nil }
|
||||
func (d *dummyFile) Name() string { return "" }
|
||||
func (d *dummyFile) Stat() (FileInfo, error) { return &dummyFileInfo{}, nil }
|
||||
|
||||
type dummyFilesystem struct{}
|
||||
type dummyFilesystem struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (d *dummyFilesystem) Name() string { return d.name }
|
||||
func (d *dummyFilesystem) Base() string { return "/" }
|
||||
func (d *dummyFilesystem) Rebase(string) error { return nil }
|
||||
func (d *dummyFilesystem) Type() string { return "dummy" }
|
||||
@ -36,6 +39,8 @@ func (d *dummyFilesystem) DeleteAll() int64 { return
|
||||
func (d *dummyFilesystem) List(string) []FileInfo { return []FileInfo{} }
|
||||
|
||||
// NewDummyFilesystem return a dummy filesystem
|
||||
func NewDummyFilesystem() Filesystem {
|
||||
return &dummyFilesystem{}
|
||||
func NewDummyFilesystem(name string) Filesystem {
|
||||
return &dummyFilesystem{
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,9 @@ type File interface {
|
||||
|
||||
// Filesystem is an interface that provides access to a filesystem.
|
||||
type Filesystem interface {
|
||||
// Name returns the name of this filesystem
|
||||
Name() string
|
||||
|
||||
// Base returns the base path of this filesystem
|
||||
Base() string
|
||||
|
||||
|
||||
@ -15,6 +15,9 @@ import (
|
||||
// MemConfig is the config that is required for creating
|
||||
// a new memory filesystem.
|
||||
type MemConfig struct {
|
||||
// Namee is the name of the filesystem
|
||||
Name string
|
||||
|
||||
// Base is the base path to be reported for this filesystem
|
||||
Base string
|
||||
|
||||
@ -107,6 +110,7 @@ func (f *memFile) Close() error {
|
||||
}
|
||||
|
||||
type memFilesystem struct {
|
||||
name string
|
||||
base string
|
||||
|
||||
// Mapping of path to file
|
||||
@ -136,6 +140,7 @@ type memFilesystem struct {
|
||||
// the Filesystem interface.
|
||||
func NewMemFilesystem(config MemConfig) Filesystem {
|
||||
fs := &memFilesystem{
|
||||
name: config.Name,
|
||||
base: config.Base,
|
||||
maxSize: config.Size,
|
||||
purge: config.Purge,
|
||||
@ -164,6 +169,10 @@ func NewMemFilesystem(config MemConfig) Filesystem {
|
||||
return fs
|
||||
}
|
||||
|
||||
func (fs *memFilesystem) Name() string {
|
||||
return fs.name
|
||||
}
|
||||
|
||||
func (fs *memFilesystem) Base() string {
|
||||
return fs.base
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
)
|
||||
|
||||
type S3Config struct {
|
||||
// Namee is the name of the filesystem
|
||||
Name string
|
||||
Base string
|
||||
Endpoint string
|
||||
AccessKeyID string
|
||||
@ -25,6 +27,7 @@ type S3Config struct {
|
||||
}
|
||||
|
||||
type s3fs struct {
|
||||
name string
|
||||
base string
|
||||
|
||||
endpoint string
|
||||
@ -41,6 +44,7 @@ type s3fs struct {
|
||||
|
||||
func NewS3Filesystem(config S3Config) (Filesystem, error) {
|
||||
fs := &s3fs{
|
||||
name: config.Name,
|
||||
base: config.Base,
|
||||
endpoint: config.Endpoint,
|
||||
accessKeyID: config.AccessKeyID,
|
||||
@ -101,6 +105,10 @@ func NewS3Filesystem(config S3Config) (Filesystem, error) {
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
func (fs *s3fs) Name() string {
|
||||
return fs.name
|
||||
}
|
||||
|
||||
func (fs *s3fs) Base() string {
|
||||
return fs.base
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user