2020-01-04 21:22:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
2020-02-07 16:08:57 +00:00
|
|
|
type portalConfig struct {
|
2020-01-04 21:22:45 +00:00
|
|
|
Command string
|
|
|
|
Host []string `yaml:",flow"`
|
|
|
|
}
|
|
|
|
|
2020-02-07 16:08:57 +00:00
|
|
|
type appConfig struct {
|
|
|
|
Portals map[string]*portalConfig
|
2020-01-04 21:22:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 16:08:57 +00:00
|
|
|
var config = &appConfig{}
|
2020-01-04 21:22:45 +00:00
|
|
|
|
|
|
|
func readConfig(configPath string) error {
|
|
|
|
configData, err := ioutil.ReadFile(configPath)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to read file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Unmarshal(configData, config)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to parse file: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(config.Portals) == 0 {
|
|
|
|
log.Println("Warning: No portals are defined")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|