diff --git a/bird/bird.go b/bird/bird.go index 216c301..439462c 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -28,7 +28,7 @@ var Cache = struct { var NilParse Parsed = (Parsed)(nil) var BirdError Parsed = Parsed{"error": "bird unreachable"} -func isSpecial(ret Parsed) bool { +func IsSpecial(ret Parsed) bool { return reflect.DeepEqual(ret, NilParse) || reflect.DeepEqual(ret, BirdError) } @@ -133,7 +133,7 @@ func RunAndParse(cmd string, parser func(io.Reader) Parsed) (Parsed, bool) { func Status() (Parsed, bool) { birdStatus, from_cache := RunAndParse("status", parseStatus) - if isSpecial(birdStatus) { + if IsSpecial(birdStatus) { return birdStatus, from_cache } @@ -178,7 +178,7 @@ func Protocols() (Parsed, bool) { func ProtocolsBgp() (Parsed, bool) { protocols, from_cache := Protocols() - if isSpecial(protocols) { + if IsSpecial(protocols) { return protocols, from_cache } @@ -211,7 +211,7 @@ func RoutesProto(protocol string) (Parsed, bool) { func RoutesProtoCount(protocol string) (Parsed, bool) { cmd := routeQueryForChannel("route protocol "+protocol) + " count" - return RunAndParse(cmd, parseRoutes) + return RunAndParse(cmd, parseRoutesCount) } func RoutesFiltered(protocol string) (Parsed, bool) { diff --git a/endpoints/symbols.go b/endpoints/symbols.go index d41ffe9..df9245b 100644 --- a/endpoints/symbols.go +++ b/endpoints/symbols.go @@ -1,7 +1,6 @@ package endpoints import ( - "reflect" "net/http" "github.com/alice-lg/birdwatcher/bird" @@ -14,7 +13,7 @@ func Symbols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { func SymbolTables(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { val, from_cache := bird.Symbols() - if reflect.DeepEqual(val, bird.NilParse) || reflect.DeepEqual(val, bird.BirdError) { + if bird.IsSpecial(val) { return val, from_cache } return bird.Parsed{"symbols": val["symbols"].(bird.Parsed)["routing table"]}, from_cache @@ -22,7 +21,7 @@ func SymbolTables(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { func SymbolProtocols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) { val, from_cache := bird.Symbols() - if reflect.DeepEqual(val, bird.NilParse) || reflect.DeepEqual(val, bird.BirdError) { + if bird.IsSpecial(val) { return val, from_cache } return bird.Parsed{"symbols": val["symbols"].(bird.Parsed)["protocol"]}, from_cache