-
Notifications
You must be signed in to change notification settings - Fork 39
/
config.go
45 lines (38 loc) · 1.04 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"io/ioutil"
"github.com/pelletier/go-toml"
)
type macAddress string
type brconfig struct {
NetInterface string `toml:"net_interface"`
Devices map[macAddress]bonjourDevice `toml:"devices"`
}
type bonjourDevice struct {
OriginPool uint16 `toml:"origin_pool"`
SharedPools []uint16 `toml:"shared_pools"`
}
func readConfig(path string) (cfg brconfig, err error) {
content, err := ioutil.ReadFile(path)
if err != nil {
return brconfig{}, err
}
err = toml.Unmarshal(content, &cfg)
return cfg, err
}
func mapByPool(devices map[macAddress]bonjourDevice) map[uint16]([]uint16) {
seen := make(map[uint16]map[uint16]bool)
poolsMap := make(map[uint16]([]uint16))
for _, device := range devices {
for _, pool := range device.SharedPools {
if _, ok := seen[pool]; !ok {
seen[pool] = make(map[uint16]bool)
}
if _, ok := seen[pool][device.OriginPool]; !ok {
seen[pool][device.OriginPool] = true
poolsMap[pool] = append(poolsMap[pool], device.OriginPool)
}
}
}
return poolsMap
}