Skip to content

Commit

Permalink
share common calling path in printKeyValue
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Che <drc@yahoo-inc.com>
  • Loading branch information
Derek Che committed Jan 4, 2015
1 parent 03377c6 commit a243bba
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

3 comments on commit a243bba

@rasky
Copy link
Contributor

@rasky rasky commented on a243bba Jan 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the it now prints the key/value two times when it's neither a string nor an error.

@sirupsen
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, yes. I'll take a look.

@sirupsen
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like that's the case anymore in latest master.

Please sign in to comment.