From a243bbaa0b2e5314bf8e53831d9e0c1afa67de51 Mon Sep 17 00:00:00 2001 From: Derek Che Date: Sun, 4 Jan 2015 00:01:49 -0800 Subject: [PATCH] share common calling path in printKeyValue Signed-off-by: Derek Che --- text_formatter.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/text_formatter.go b/text_formatter.go index bbf6110..ce19ead 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -107,18 +107,16 @@ func needsQuoting(text string) bool { func printKeyValue(b *bytes.Buffer, key, value interface{}) { switch value.(type) { case string: - if needsQuoting(value.(string)) { - fmt.Fprintf(b, "%v=%s ", key, value) - } else { - fmt.Fprintf(b, "%v=%q ", key, value) - } + break case error: - if needsQuoting(value.(error).Error()) { - fmt.Fprintf(b, "%v=%s ", key, value) - } else { - fmt.Fprintf(b, "%v=%q ", key, value) - } + value = value.(error).Error() default: fmt.Fprintf(b, "%v=%v ", key, value) } + + if needsQuoting(value.(string)) { + fmt.Fprintf(b, "%v=%s ", key, value) + } else { + fmt.Fprintf(b, "%v=%q ", key, value) + } }