/
config.go
39 lines (36 loc) · 1.07 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
package main
import (
"emperror.dev/errors"
"github.com/BurntSushi/toml"
"github.com/je4/trustutil/v2/pkg/loader"
"io/fs"
"os"
)
type MediaserverAPIConfig struct {
LocalAddr string `toml:"localaddr"`
ExternalAddr string `toml:"externaladdr"`
Server *loader.TLSConfig `toml:"server"`
Client *loader.TLSConfig `toml:"client"`
LogFile string `toml:"logfile"`
LogLevel string `toml:"loglevel"`
GRPCClient map[string]string `toml:"grpcclient"`
}
func LoadMediaserverAPIConfig(fSys fs.FS, fp string, conf *MediaserverAPIConfig) 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 = "mediaserverapi.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
}