Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/human/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ func marshalStruct(value reflect.Value, opt *MarshalOpt) (string, error) {
}

return data, nil
case rType.Kind() == reflect.Interface:
// If type is interface{}
// marshal the underlying type
return marshal(value.Elem(), keys)
default:
str, err := defaultMarshalerFunc(value.Interface(), subOpts)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions internal/human/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ type Struct struct {
Size *scw.Size
}

type StructAny struct {
String interface{}
StringPtr interface{}
Map map[string]interface{}
MapPtr map[string]interface{}
}

type Address struct {
Street string
City string
Expand Down Expand Up @@ -184,6 +191,26 @@ func TestMarshal(t *testing.T) {
},
result: `Name Paul`,
}))

var testAnyString = "MyString"
t.Run("any", run(&testCase{
data: &StructAny{
String: testAnyString,
StringPtr: &testAnyString,
Map: map[string]interface{}{
"String": testAnyString,
},
MapPtr: map[string]interface{}{
"String": &testAnyString,
},
},
result: `
String MyString
StringPtr MyString
Map.String MyString
MapPtr.String MyString
`,
}))
}

func Test_getStructFieldsIndex(t *testing.T) {
Expand Down