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