Skip to content

Commit

Permalink
Merge 8b9e482 into 101387a
Browse files Browse the repository at this point in the history
  • Loading branch information
cscatolini committed Sep 18, 2019
2 parents 101387a + 8b9e482 commit 56cd25d
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions plugins/grpc/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,30 +327,35 @@ func (g *GRPCForwarder) configure() error {
}

func (g *GRPCForwarder) mergeInfos(infos, fwdMetadata map[string]interface{}) map[string]interface{} {
if fwdMetadata != nil {
if roomType, ok := fwdMetadata["roomType"]; ok {
if metadata, ok := infos["metadata"].(map[string]interface{}); ok {
if metadata != nil {
metadata["roomType"] = roomType
} else {
infos["metadata"] = map[string]interface{}{"roomType": roomType}
}
} else if metadata, ok := infos["metadata"].(map[interface{}]interface{}); ok {
if metadata != nil {
metadata["roomType"] = roomType
} else {
infos["metadata"] = map[string]interface{}{"roomType": roomType}
}
} else if infos["metadata"] == nil {
infos["metadata"] = map[string]interface{}{"roomType": roomType}
} else {
g.logger.WithFields(log.Fields{
"op": "mergeInfos",
"metadata": fmt.Sprintf("%T", infos["metadata"]),
}).Warn("invalid metadata provided")
}
if fwdMetadata == nil {
return infos
}

metadata := infos["metadata"]
if metadata == nil {
metadata = map[string]interface{}{}
}

if m, ok := metadata.(map[string]interface{}); ok {
for k, v := range fwdMetadata {
m[k] = v
}
infos["metadata"] = m
return infos
}

if m, ok := metadata.(map[interface{}]interface{}); ok {
for k, v := range fwdMetadata {
m[k] = v
}
infos["metadata"] = m
return infos
}

g.logger.WithFields(log.Fields{
"op": "mergeInfos",
"metadata": fmt.Sprintf("%T", infos["metadata"]),
}).Warn("invalid metadata provided")
return infos
}

Expand Down

0 comments on commit 56cd25d

Please sign in to comment.