Skip to content

Commit

Permalink
Merge pull request #33 from icholy/master
Browse files Browse the repository at this point in the history
use hex encoding for byte slice
  • Loading branch information
novln authored Mar 9, 2018
2 parents 1c6880f + 0af0e8d commit b658af1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package format

import (
"bytes"
"encoding/hex"
"fmt"
"strconv"
"time"
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b658af1

Please sign in to comment.