2022-02-06 02:22:23 +04:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration holds a list of process names to be tracked and a listen address.
|
|
|
|
type Configuration struct {
|
|
|
|
ListenOn string `yaml:"listen_on"`
|
|
|
|
Uploads struct {
|
|
|
|
Directory string `yaml:"directory"`
|
|
|
|
Limits struct {
|
|
|
|
FileSize string `yaml:"file_size"`
|
|
|
|
KeepForHours int `yaml:"keep_for_hours"`
|
|
|
|
Storage string `yaml:"storage"`
|
|
|
|
} `yaml:"limits"`
|
|
|
|
} `yaml:"uploads"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfiguration(path string) (*Configuration, error) {
|
2022-02-06 03:01:16 +04:00
|
|
|
configFile, err := os.Open(path)
|
2022-02-06 02:22:23 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to open configuration file")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := &Configuration{}
|
|
|
|
|
2022-02-06 03:01:16 +04:00
|
|
|
if err := yaml.NewDecoder(configFile).Decode(config); err != nil {
|
2022-02-06 02:22:23 +04:00
|
|
|
return nil, errors.Wrap(err, "failed to decode configuration file")
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Configuration) SplitNetworkAddress() (n string, a string) {
|
|
|
|
s := strings.Split(c.ListenOn, " ")
|
|
|
|
n, a = s[0], s[1]
|
|
|
|
return n, a
|
|
|
|
}
|