Reduce duplicate code

This commit is contained in:
Paul Seiffert 2017-07-12 17:16:13 +02:00
parent b9cfd82645
commit 4c4851c96a
No known key found for this signature in database
GPG Key ID: C9F76DC911D6EA29
1 changed files with 11 additions and 17 deletions

View File

@ -169,27 +169,21 @@ func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interf
} }
func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) { func (f *TextFormatter) appendValue(b *bytes.Buffer, value interface{}) {
var stringVal string
switch value := value.(type) { switch value := value.(type) {
case string: case string:
if !f.needsQuoting(value) { stringVal = value
b.WriteString(value)
} else {
b.WriteString(f.quoteString(value))
}
case error: case error:
errmsg := value.Error() stringVal = value.Error()
if !f.needsQuoting(errmsg) {
b.WriteString(errmsg)
} else {
b.WriteString(f.quoteString(errmsg))
}
default: default:
s := fmt.Sprint(value) stringVal = fmt.Sprint(value)
if !f.needsQuoting(s) {
b.WriteString(s)
} else {
b.WriteString(f.quoteString(s))
} }
if !f.needsQuoting(stringVal) {
b.WriteString(stringVal)
} else {
b.WriteString(f.quoteString(stringVal))
} }
} }