From 0af0e8d95b13216215cf4147297c71ac93ff74c6 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 8 Mar 2018 11:00:55 -0500 Subject: [PATCH] use hex encoding for byte slice --- format/format.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/format/format.go b/format/format.go index c4c957f..23102e8 100644 --- a/format/format.go +++ b/format/format.go @@ -2,6 +2,7 @@ package format import ( "bytes" + "encoding/hex" "fmt" "strconv" "time" @@ -13,7 +14,7 @@ func Value(arg interface{}) string { // nolint: gocyclo case string: return String(value) case []byte: - return String(string(value)) + return Bytes(value) case time.Time: return Time(value) case int: @@ -71,6 +72,12 @@ func String(value string) string { // nolint: errcheck return buffer.String() } +// Bytes formats the give bytes. +func Bytes(value []byte) string { + encoded := hex.EncodeToString(value) + return fmt.Sprintf("decode('%s', 'hex')", encoded) +} + // Int formats the given number. func Int(value int64) string { return strconv.FormatInt(value, 10)