mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
Add metadata Get method (#1425)
This commit is contained in:
parent
329bd09f93
commit
e204f3e2e8
@ -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)
|
||||
|
@ -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?
|
||||
|
Loading…
Reference in New Issue
Block a user