summaryrefslogtreecommitdiff
path: root/src/rhctl/conf.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl/conf.go')
-rw-r--r--src/rhctl/conf.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index 77ab174..bbf546c 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -22,24 +22,32 @@
package main
import (
+ "errors"
"os"
+ "sort"
"strings"
"time"
"github.com/naoina/toml"
)
+type ConfigSwitchPorts []struct {
+ Number SwitchInputNum `toml:"number"`
+ Server string `toml:"server"`
+ Channel string `toml:"channel"`
+}
+
+func (p ConfigSwitchPorts) Len() int { return len(p) }
+func (p ConfigSwitchPorts) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+func (p ConfigSwitchPorts) Less(i, j int) bool { return p[i].Number < p[j].Number }
+
type Config struct {
Audioswitch struct {
- Device string `toml:"dev"`
- Baudrate Baudrate `toml:"baud"`
- Timeout Duration `toml:"timeout"`
- Unit SwitchUnitID `toml:"unit"`
- Ports []struct {
- Server string `toml:"server"`
- Channel string `toml:"channel"`
- Number SwitchInputNum `toml:"number"`
- }
+ Device string `toml:"dev"`
+ Baudrate Baudrate `toml:"baud"`
+ Timeout Duration `toml:"timeout"`
+ Unit SwitchUnitID `toml:"unit"`
+ Ports ConfigSwitchPorts `toml:"ports"`
}
Servers map[string]struct {
@@ -84,5 +92,13 @@ func ReadConfig(configfile string) (conf *Config, err error) {
if err = decoder.Decode(conf); err != nil {
return
}
+
+ sort.Sort(conf.Audioswitch.Ports)
+ for i := 1; i < len(conf.Audioswitch.Ports); i++ {
+ if conf.Audioswitch.Ports[i].Number == conf.Audioswitch.Ports[i-1].Number {
+ return nil, errors.New("audioswitch port assignments must be unique")
+ }
+ }
+
return
}