go-playground / form

:steam_locomotive: Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
MIT License
758 stars 41 forks source link

Feature: support "natural" maps #52

Open mihaiav opened 3 years ago

mihaiav commented 3 years ago

It seems that map types are not supported. E.g. map[interface{}]interface{} or map[string]string. Is this the expected behaviour?

Play

package main

import (
    "fmt"
    "github.com/go-playground/form"
    "net/url"
    "reflect"
)

func main() {
    dec := form.NewDecoder()

    req := url.Values{"a": []string{"a"}, "b": []string{"b"}, "c": []string{"1"}}

    v := map[interface{}]interface{}{
        "a": "",
        "b": "",
        "c": 0,
    }

    expected := map[interface{}]interface{}{
        "a": "a",
        "b": "b",
        "c": 1,
    }
    if err := dec.Decode(&v, req); err != nil {
        panic(err)
    }
    if !reflect.DeepEqual(v, expected) {
        fmt.Printf("expected\n %#v\n received\n %#v", expected, v)
    }
}