Skip to content

Commit

Permalink
feat(tdp): improve slice handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Mar 2, 2021
1 parent 4dcac41 commit 4eb1e05
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tdp/tdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package tdp

import (
"encoding/base64"
"fmt"
"reflect"
"strconv"
Expand Down Expand Up @@ -37,13 +38,19 @@ func formatValue(b *strings.Builder, prefix string, opt options, v reflect.Value
formatValue(b, prefix, opt, v.Addr())
}
case reflect.Slice:
if buf, ok := v.Interface().([]byte); ok {
b.WriteString(base64.RawURLEncoding.EncodeToString(buf))
return
}

b.WriteRune('\n')
b.WriteString(prefix)
for i := 0; i < v.Len(); i++ {
vi := v.Index(i)
b.WriteString(prefix)
b.WriteString(defaultIdent)
b.WriteString("- ")
formatValue(b, prefix+defaultIdent, opt, vi)
b.WriteRune('\n')
}
default:
b.WriteString(fmt.Sprint(v.Interface()))
Expand Down

0 comments on commit 4eb1e05

Please sign in to comment.