Removed Configuration.
This commit is contained in:
parent
931f98d12e
commit
332e9a1bb3
@ -1,54 +0,0 @@
|
|||||||
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"`
|
|
||||||
HashSalt string `yaml:"hash_salt"`
|
|
||||||
User string `yaml:"user"`
|
|
||||||
Log struct {
|
|
||||||
Error string `yaml:"error"`
|
|
||||||
File string `yaml:"file"`
|
|
||||||
Clean string `yaml:"clean"`
|
|
||||||
CleanError string `yaml:"clean_error"`
|
|
||||||
} `yaml:"log"`
|
|
||||||
Uploads struct {
|
|
||||||
Directory string `yaml:"directory"`
|
|
||||||
Limits struct {
|
|
||||||
FileSize int64 `yaml:"file_size"`
|
|
||||||
KeepForHours int `yaml:"keep_for_hours"`
|
|
||||||
Storage int64 `yaml:"storage"`
|
|
||||||
} `yaml:"limits"`
|
|
||||||
} `yaml:"uploads"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadConfiguration(path string) (*Configuration, error) {
|
|
||||||
configFile, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to open configuration file")
|
|
||||||
}
|
|
||||||
defer configFile.Close()
|
|
||||||
|
|
||||||
config := &Configuration{}
|
|
||||||
|
|
||||||
if err := yaml.NewDecoder(configFile).Decode(config); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "failed to parse configuration file")
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SplitNetworkAddress splits ListenOn option and returns as two strings
|
|
||||||
// network type (e.g. tcp, unix, udp) and address:port or /path/to/prog.socket
|
|
||||||
// to listen on.
|
|
||||||
func (c *Configuration) SplitNetworkAddress() (string, string) {
|
|
||||||
s := strings.Split(c.ListenOn, " ")
|
|
||||||
return s[0], s[1]
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user