Add metadata Get method (#1425)
This commit is contained in:
parent
329bd09f93
commit
e204f3e2e8
@ -13,6 +13,18 @@ type metaKey struct{}
|
|||||||
// from Transport headers.
|
// from Transport headers.
|
||||||
type Metadata map[string]string
|
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
|
// Copy makes a copy of the metadata
|
||||||
func Copy(md Metadata) Metadata {
|
func Copy(md Metadata) Metadata {
|
||||||
cmd := make(Metadata)
|
cmd := make(Metadata)
|
||||||
|
@ -120,7 +120,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
|
|||||||
// filter the routes based on our headers
|
// filter the routes based on our headers
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
// process only routes for this id
|
// 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 {
|
if route.Router != id {
|
||||||
// skip routes that don't mwatch
|
// skip routes that don't mwatch
|
||||||
continue
|
continue
|
||||||
@ -128,7 +128,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only process routes with this network
|
// 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 {
|
if route.Network != net {
|
||||||
// skip routes that don't mwatch
|
// skip routes that don't mwatch
|
||||||
continue
|
continue
|
||||||
@ -136,7 +136,7 @@ func (p *Proxy) filterRoutes(ctx context.Context, routes []router.Route) []route
|
|||||||
}
|
}
|
||||||
|
|
||||||
// process only this gateway
|
// 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
|
// if the gateway matches our address
|
||||||
// special case, take the routes with no gateway
|
// special case, take the routes with no gateway
|
||||||
// TODO: should we strip the gateway from the context?
|
// TODO: should we strip the gateway from the context?
|
||||||
|
Loading…
Reference in New Issue
Block a user