diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 05:59:42 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-25 05:59:42 -0800 |
commit | d9d527a65dd068e0a093ed94ad5effc13567a5e1 (patch) | |
tree | 389a48290c084887a85e43918971ebdfff2bc5f8 | |
parent | 40819efb0c592d8a23da8bec0006014b43321ac4 (diff) |
table: make table json prettier
Even 'jq' command makes the output very nicer.
$ curl http://localhost:8080/v1/bgp/neighbor/10.0.0.1/local-rib |jq '.'
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | table/destination.go | 5 | ||||
-rw-r--r-- | table/path.go | 5 | ||||
-rw-r--r-- | table/table.go | 5 |
3 files changed, 6 insertions, 9 deletions
diff --git a/table/destination.go b/table/destination.go index f90a53fa..f99af8ef 100644 --- a/table/destination.go +++ b/table/destination.go @@ -95,13 +95,12 @@ func NewDestinationDefault(nlri bgp.AddrPrefixInterface) *DestinationDefault { func (dd *DestinationDefault) MarshalJSON() ([]byte, error) { prefix := dd.getNlri().(*bgp.NLRInfo).Prefix - paths, _ := json.Marshal(dd.knownPathList) return json.Marshal(struct { Prefix string - Paths string + Paths []Path }{ Prefix: prefix.String(), - Paths: string(paths), + Paths: dd.knownPathList, }) } diff --git a/table/path.go b/table/path.go index 9b38bc44..635cbf5d 100644 --- a/table/path.go +++ b/table/path.go @@ -97,7 +97,6 @@ func (pd *PathDefault) MarshalJSON() ([]byte, error) { aslist = append(aslist, path.AS...) } } - asPath, _ := json.Marshal(aslist) var prefix net.IP var prefixLen uint8 @@ -110,7 +109,7 @@ func (pd *PathDefault) MarshalJSON() ([]byte, error) { return json.Marshal(struct { Network string Nexthop string - AsPath string + AsPath []uint32 Metric string //origin string Best string @@ -118,7 +117,7 @@ func (pd *PathDefault) MarshalJSON() ([]byte, error) { Network: prefix.String() + "/" + fmt.Sprint(prefixLen), Nexthop: pd.nexthop.String(), Metric: fmt.Sprint(med), - AsPath: string(asPath), + AsPath: aslist, Best: fmt.Sprint(pd.isBest), }) } diff --git a/table/table.go b/table/table.go index df55947b..a9d742aa 100644 --- a/table/table.go +++ b/table/table.go @@ -55,12 +55,11 @@ func (td *TableDefault) MarshalJSON() ([]byte, error) { for _, dest := range td.destinations { destList = append(destList, dest) } - j, _ := json.Marshal(destList) return json.Marshal(struct { - Destinations string + Destinations []Destination }{ - Destinations: string(j), + Destinations: destList, }) } |