diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2018-04-18 23:50:42 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2018-04-18 23:50:42 -0400 |
| commit | e142ace1394fe56eec1cfdfb1c8a3db0efb6ff9f (patch) | |
| tree | 01498625109f9f92d82996864399ff1e3a5f088c /funcs/base64.go | |
| parent | 3813bd30819c13047f385637d0f038dc84277633 (diff) | |
Relax inputs for many functions
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'funcs/base64.go')
| -rw-r--r-- | funcs/base64.go | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/funcs/base64.go b/funcs/base64.go index b66f7a08..8d744022 100644 --- a/funcs/base64.go +++ b/funcs/base64.go @@ -1,11 +1,10 @@ package funcs import ( - "fmt" - "strconv" "sync" "github.com/hairyhenderson/gomplate/base64" + "github.com/hairyhenderson/gomplate/conv" ) var ( @@ -35,7 +34,7 @@ func (f *Base64Funcs) Encode(in interface{}) string { // Decode - func (f *Base64Funcs) Decode(in interface{}) string { - return string(base64.Decode(toString(in))) + return string(base64.Decode(conv.ToString(in))) } type byter interface { @@ -55,30 +54,5 @@ func toBytes(in interface{}) []byte { if s, ok := in.(string); ok { return []byte(s) } - return []byte(fmt.Sprintf("%s", in)) -} - -func toString(in interface{}) string { - if s, ok := in.(string); ok { - return s - } - if s, ok := in.(fmt.Stringer); ok { - return s.String() - } - if i, ok := in.(int); ok { - return strconv.Itoa(i) - } - if u, ok := in.(uint64); ok { - return strconv.FormatUint(u, 10) - } - if f, ok := in.(float64); ok { - return strconv.FormatFloat(f, 'f', -1, 64) - } - if b, ok := in.(bool); ok { - return strconv.FormatBool(b) - } - if in == nil { - return "nil" - } - return fmt.Sprintf("%s", in) + return []byte(conv.ToString(in)) } |
