-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (45 loc) · 1.61 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"emperror.dev/errors"
"github.com/BurntSushi/toml"
"github.com/je4/filesystem/v2/pkg/vfsrw"
"github.com/je4/indexer/v2/pkg/indexer"
"github.com/je4/trustutil/v2/pkg/loader"
configutil "github.com/je4/utils/v2/pkg/config"
"io/fs"
"os"
)
type MediaserverIngestConfig struct {
LocalAddr string `toml:"localaddr"`
ResolverAddr string `toml:"resolveraddr"`
ResolverTimeout configutil.Duration `toml:"resolvertimeout"`
ResolverNotFoundTimeout configutil.Duration `toml:"resolvernotfoundtimeout"`
LogFile string `toml:"logfile"`
LogLevel string `toml:"loglevel"`
IngestTimeout configutil.Duration `toml:"ingesttimeout"`
IngestWait configutil.Duration `toml:"ingestwait"`
ConcurrentTasks int `toml:"concurrenttasks"`
GRPCClient map[string]string `toml:"grpcclient"`
ClientTLS *loader.TLSConfig `toml:"client"`
Indexer *indexer.IndexerConfig
VFS map[string]*vfsrw.VFS `toml:"vfs"`
}
func LoadMediaserverIngestConfig(fSys fs.FS, fp string, conf *MediaserverIngestConfig) error {
if _, err := fs.Stat(fSys, fp); err != nil {
path, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "cannot get current working directory")
}
fSys = os.DirFS(path)
fp = "mediaserveringest.toml"
}
data, err := fs.ReadFile(fSys, fp)
if err != nil {
return errors.Wrapf(err, "cannot read file [%v] %s", fSys, fp)
}
_, err = toml.Decode(string(data), conf)
if err != nil {
return errors.Wrapf(err, "error loading config file %v", fp)
}
return nil
}