1
0
Fork 0

Also moved a Configuration struct to main.go.

This commit is contained in:
Alexander Andreev 2024-01-13 04:42:19 +04:00
parent 64b5966b48
commit 37bc8b0f1b
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 31 additions and 38 deletions

View File

@ -1,38 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
type Configuration struct {
ListenAddress string `json:"listen-address"`
Processes []Process `json:"processes"`
}
func LoadConfiguration(path string) (conf *Configuration, err error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
conf = &Configuration{}
if err := json.NewDecoder(f).Decode(conf); err != nil {
return nil, err
}
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
}
}
return conf, nil
}

31
main.go
View File

@ -41,6 +41,37 @@ func GetProcessesState(procs *[]Process) (ps ProcessesState) {
return
}
type Configuration struct {
ListenAddress string `json:"listen-address"`
Processes []Process `json:"processes"`
}
func LoadConfiguration(path string) (conf *Configuration, err error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
conf = &Configuration{}
if err := json.NewDecoder(f).Decode(conf); err != nil {
return nil, err
}
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
}
}
return conf, nil
}
func main() {
log.SetFlags(0)
flag.Parse()