Add efficient implementation of fmt and use for errors.

This commit is contained in:
Jae Kwon
2018-03-17 15:23:03 +01:00
parent bb875303c2
commit 99437a96fb
2 changed files with 20 additions and 8 deletions

View File

@ -6,8 +6,14 @@ import (
"strings"
)
// Fmt shorthand, XXX DEPRECATED
var Fmt = fmt.Sprintf
// Like fmt.Sprintf, but skips formatting if args are empty.
var Fmt = func(format string, a ...interface{}) string {
if len(a) == 0 {
return format
} else {
return fmt.Sprintf(format, a...)
}
}
// RightPadString adds spaces to the right of a string to make it length totalLength
func RightPadString(s string, totalLength int) string {