fix GetString for metadata
This commit is contained in:
@ -79,9 +79,29 @@ func GetDuration(md metadata.Metadata, key string) (v time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetString(md metadata.Metadata, key string) (v string) {
|
func GetString(md metadata.Metadata, key string) (v string) {
|
||||||
if md != nil {
|
if md == nil || !md.IsExists(key) {
|
||||||
v, _ = md.Get(key).(string)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch vv := md.Get(key).(type) {
|
||||||
|
case string:
|
||||||
|
v = vv
|
||||||
|
case int:
|
||||||
|
v = strconv.FormatInt(int64(vv), 10)
|
||||||
|
case int64:
|
||||||
|
v = strconv.FormatInt(vv, 10)
|
||||||
|
case uint:
|
||||||
|
v = strconv.FormatUint(uint64(vv), 10)
|
||||||
|
case uint64:
|
||||||
|
v = strconv.FormatUint(uint64(vv), 10)
|
||||||
|
case bool:
|
||||||
|
v = strconv.FormatBool(vv)
|
||||||
|
case float32:
|
||||||
|
v = strconv.FormatFloat(float64(vv), 'f', -1, 32)
|
||||||
|
case float64:
|
||||||
|
v = strconv.FormatFloat(float64(vv), 'f', -1, 64)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user