share common calling path in printKeyValue

Signed-off-by: Derek Che <drc@yahoo-inc.com>
This commit is contained in:
Derek Che 2015-01-04 00:01:49 -08:00
parent 03377c6168
commit a243bbaa0b
1 changed files with 8 additions and 10 deletions

View File

@ -107,18 +107,16 @@ func needsQuoting(text string) bool {
func printKeyValue(b *bytes.Buffer, key, value interface{}) { func printKeyValue(b *bytes.Buffer, key, value interface{}) {
switch value.(type) { switch value.(type) {
case string: case string:
break
case error:
value = value.(error).Error()
default:
fmt.Fprintf(b, "%v=%v ", key, value)
}
if needsQuoting(value.(string)) { if needsQuoting(value.(string)) {
fmt.Fprintf(b, "%v=%s ", key, value) fmt.Fprintf(b, "%v=%s ", key, value)
} else { } else {
fmt.Fprintf(b, "%v=%q ", key, value) fmt.Fprintf(b, "%v=%q ", key, value)
} }
case error:
if needsQuoting(value.(error).Error()) {
fmt.Fprintf(b, "%v=%s ", key, value)
} else {
fmt.Fprintf(b, "%v=%q ", key, value)
}
default:
fmt.Fprintf(b, "%v=%v ", key, value)
}
} }