Alanxtl commented on code in PR #3433:
URL: https://github.com/apache/dubbo-go/pull/3433#discussion_r3540765644
##########
filter/otel/trace/attachment.go:
##########
@@ -39,21 +39,26 @@ func (s *metadataSupplier) Get(key string) string {
if s.metadata == nil {
return ""
}
- item, ok := s.metadata[key].([]string)
- if !ok {
+ val, ok := s.metadata[key]
+ if !ok || val == nil {
return ""
}
- if len(item) == 0 {
- return ""
+ // Handle []string (produced by triple's generateAttachments and by Set
below)
+ if item, ok := val.([]string); ok && len(item) > 0 {
+ return item[0]
+ }
+ // Handle string (defensive: for any externally-set string values)
+ if str, ok := val.(string); ok {
+ return str
}
- return item[0]
+ return ""
}
Review Comment:
use type switch instead, which like
```
switch t := value.(type){
case int64:
// if type is an integer
fmt.Println("Type is an integer:", t)
case float64:
// if type is a floating point number
fmt.Println("Type is a float:", t)
default:
// if type is other than above
fmt.Println("Type is unknown!")
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]