Add metadata Get method (#1425)

This commit is contained in:
Asim Aslam 2020-03-26 18:50:00 +00:00 committed by GitHub
parent 329bd09f93
commit e204f3e2e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -13,6 +13,18 @@ type metaKey struct{}
// from Transport headers.
type Metadata map[string]string
func (md Metadata) Get(key string) (string, bool) {
// attempt to get as is
val, ok := md[key]
if ok {
return val, ok
}
// attempt to get lower case
val, ok = md[strings.Title(key)]
return val, ok
}
// Copy makes a copy of the metadata
func Copy(md Metadata) Metadata {
cmd := make(Metadata)

View File

@ -120,7 +120,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
// filter the routes based on our headers
for _, route := range routes {
// process only routes for this id
if id := md["Micro-Router"]; len(id) > 0 {
if id, ok := md.Get("Micro-Router"); ok && len(id) > 0 {
if route.Router != id {
// skip routes that don't mwatch
continue
@ -128,7 +128,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
}
// only process routes with this network
if net := md["Micro-Network"]; len(net) > 0 {
if net, ok := md.Get("Micro-Network"); ok && len(net) > 0 {
if route.Network != net {
// skip routes that don't mwatch
continue
@ -136,7 +136,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
}
// process only this gateway
if gw := md["Micro-Gateway"]; len(gw) > 0 {
if gw, ok := md.Get("Micro-Gateway"); ok && len(gw) > 0 {
// if the gateway matches our address
// special case, take the routes with no gateway
// TODO: should we strip the gateway from the context?