2022-01-02 21:30:56 +04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-15 04:00:26 +04:00
|
|
|
"encoding/json"
|
2023-12-16 02:22:27 +04:00
|
|
|
"fmt"
|
2022-01-02 21:30:56 +04:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Configuration struct {
|
2023-12-15 04:00:26 +04:00
|
|
|
ListenAddress string `json:"listen-address"`
|
|
|
|
Processes []Process `json:"processes"`
|
2022-01-02 21:30:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfiguration(path string) (conf *Configuration, err error) {
|
2023-12-15 04:00:26 +04:00
|
|
|
f, err := os.Open(path)
|
2022-01-02 21:30:56 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-12-15 04:00:26 +04:00
|
|
|
defer f.Close()
|
2022-01-02 21:30:56 +04:00
|
|
|
|
2023-12-15 04:00:26 +04:00
|
|
|
conf = &Configuration{}
|
2022-01-02 21:30:56 +04:00
|
|
|
|
2023-12-15 04:00:26 +04:00
|
|
|
if err := json.NewDecoder(f).Decode(conf); err != nil {
|
|
|
|
return nil, err
|
2022-01-02 21:30:56 +04:00
|
|
|
}
|
|
|
|
|
2023-12-16 02:22:27 +04:00
|
|
|
for i := 0; i < len(conf.Processes); i++ {
|
|
|
|
if conf.Processes[i].Process == "" {
|
|
|
|
return nil, fmt.Errorf("an empty process field found")
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Processes[i].Alias == "" {
|
|
|
|
conf.Processes[i].Alias = conf.Processes[i].Process
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 21:30:56 +04:00
|
|
|
return conf, nil
|
|
|
|
}
|