diff --git a/backend/bgp_communities.go b/backend/bgp_communities.go index 7b56782..5e92b03 100644 --- a/backend/bgp_communities.go +++ b/backend/bgp_communities.go @@ -138,5 +138,32 @@ func (self NgBgpCommunities) Lookup(community string) (string, error) { } func (self NgBgpCommunities) Set(community string, label string) { + path := strings.Split(community, ":") + var lookup interface{} // This is all much too dynamic... + lookup = self + for _, key := range path { + clookup, ok := lookup.(NgBgpCommunities) + if !ok { + break + } + + res, ok := clookup[key] + if !ok { + // Try to fall back to wildcard key + res, ok = clookup["*"] + if !ok { + break // we did everything we could. + } + } + + lookup = res + } + + label, ok := lookup.(string) + if !ok { + return "", fmt.Errorf("community not found") + } + + return label, nil } diff --git a/client/assets/scss/components/communities.scss b/client/assets/scss/components/communities.scss index 9e492d4..e9be6aa 100644 --- a/client/assets/scss/components/communities.scss +++ b/client/assets/scss/components/communities.scss @@ -12,3 +12,4 @@ background-color: #ddd; } +