mapstructure can decode non-maps
diff --git a/mapstructure.go b/mapstructure.go index 83676f2..5c9c196 100644 --- a/mapstructure.go +++ b/mapstructure.go
@@ -44,10 +44,6 @@ return errors.New("val must be addressable (a pointer)") } - if val.Kind() != reflect.Struct { - return errors.New("val must be an addressable struct") - } - return decode("", m, val) }
diff --git a/mapstructure_test.go b/mapstructure_test.go index f55e829..d419e7d 100644 --- a/mapstructure_test.go +++ b/mapstructure_test.go
@@ -101,6 +101,25 @@ } } +func TestDecode_NonStruct(t *testing.T) { + t.Parallel() + + input := map[string]interface{}{ + "foo": "bar", + "bar": "baz", + } + + var result map[string]string + err := Decode(input, &result) + if err != nil { + t.Fatalf("err: %s", err) + } + + if result["foo"] != "bar" { + t.Fatal("foo is not bar") + } +} + func TestMap(t *testing.T) { t.Parallel() @@ -337,20 +356,6 @@ } } -func TestNonStructValue(t *testing.T) { - t.Parallel() - - result := 42 - err := Decode(map[string]interface{}{}, &result) - if err == nil { - t.Fatal("error should exist") - } - - if err.Error() != "val must be an addressable struct" { - t.Errorf("got unexpected error: %s", err) - } -} - func TestTagged(t *testing.T) { t.Parallel()