こういうデータを処理して
eth0
link/ether 00:00:00:00:00:00
inet 192.168.0.1 brd 192.168.0.255
eth1
link/ether 11:11:11:11:11:11
inet 192.168.1.1 brd 192.168.1.255
こういう構造のmap的なものに格納したい。
{
"network": {
"interfaces": {
"eth0": {
"addresses": {
"00:00:00:00:00:00": {
"family": "lladdr"
},
"192.168.0.1": {
"broadcast": "192.168.0.255",
"family": "inet"
}
}
},
"eth1": {
"addresses": {
"11:11:11:11:11:11": {
"family": "lladdr"
},
"192.168.1.1": {
"broadcast": "192.168.1.255",
"family": "inet"
}
}
}
}
}
}
package main
import (
"fmt"
simplejson "github.com/bitly/go-simplejson"
)
func main() {
data := []string{
"eth0",
" link/ether 00:00:00:00:00:00",
" inet 192.168.0.1 brd 192.168.0.255",
"eth1",
" link/ether 11:11:11:11:11:11",
" inet 192.168.1.1 brd 192.168.1.255",
}
network := ...
// がんばる!
sj := simplejson.New()
sj.Set("network", network)
json, _ := sj.EncodePretty()
fmt.Printf("%s\n", string(json))
}