Allow to marshal pointer to struct and map (#247)
This commit is contained in:
committed by
Thomas Pelletier
parent
0a1666a81f
commit
19cbd226da
+10
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user