Allow to marshal pointer to struct and map (#247)

This commit is contained in:
Andriy Senyshyn
2018-11-19 17:31:15 +02:00
committed by Thomas Pelletier
parent 0a1666a81f
commit 19cbd226da
2 changed files with 55 additions and 6 deletions
+10 -2
View File
@@ -244,9 +244,17 @@ func (e *Encoder) SetTagMultiline(v string) *Encoder {
func (e *Encoder) marshal(v interface{}) ([]byte, error) {
mtype := reflect.TypeOf(v)
if mtype.Kind() != reflect.Struct {
return []byte{}, errors.New("Only a struct can be marshaled to TOML")
switch mtype.Kind() {
case reflect.Struct, reflect.Map:
case reflect.Ptr:
if mtype.Elem().Kind() != reflect.Struct {
return []byte{}, errors.New("Only pointer to struct can be marshaled to TOML")
}
default:
return []byte{}, errors.New("Only a struct or map can be marshaled to TOML")
}
sval := reflect.ValueOf(v)
if isCustomMarshaler(mtype) {
return callCustomMarshaler(sval)