1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Fixed /symbols endpoint.

This commit is contained in:
Patrick Seeburger 2018-09-27 13:59:40 +02:00 committed by Benedikt Rudolph
parent 439ee0d5d0
commit 6e8734fa90
2 changed files with 15 additions and 3 deletions

View file

@ -167,7 +167,12 @@ func parseSymbols(reader io.Reader) Parsed {
if regex.symbols.keyRx.MatchString(line) {
groups := regex.symbols.keyRx.FindStringSubmatch(line)
res[groups[2]] = groups[1]
if _, ok := res[groups[2]]; !ok {
res[groups[2]] = []string{}
}
res[groups[2]] = append(res[groups[2]].([]string), groups[1])
}
}

View file

@ -1,6 +1,7 @@
package endpoints
import (
"reflect"
"net/http"
"github.com/alice-lg/birdwatcher/bird"
@ -13,10 +14,16 @@ 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()
return bird.Parsed{"symbols": val["routing table"]}, from_cache
if reflect.DeepEqual(val, bird.NilParse) || reflect.DeepEqual(val, bird.BirdError) {
return val, from_cache
}
return bird.Parsed{"symbols": val["symbols"].(bird.Parsed)["routing table"]}, from_cache
}
func SymbolProtocols(r *http.Request, ps httprouter.Params) (bird.Parsed, bool) {
val, from_cache := bird.Symbols()
return bird.Parsed{"symbols": val["protocols"]}, from_cache
if reflect.DeepEqual(val, bird.NilParse) || reflect.DeepEqual(val, bird.BirdError) {
return val, from_cache
}
return bird.Parsed{"symbols": val["symbols"].(bird.Parsed)["protocol"]}, from_cache
}