Skip to content

Decoder picks only one value when array is present in query params as Array[]=x&Array[]=y #60

Closed
@ankitaSejal

Description

@ankitaSejal

Package version v3.1.4

Issue: Decoder picks only one value when the array is present in query params as Array[]=x&Array[]=y

Code sample, to showcase or reproduce:

package main

import (
	"fmt"
	"log"
	"net/url"

	"github.com/go-playground/form/v4"
)

type PostsRequest struct {
	PostIds     []string
	Projections []string
}

var decoder *form.Decoder

func main() {
	decoder = form.NewDecoder()

	values := parseForm()

	var req PostsRequest

	err := decoder.Decode(&req, values)
	if err != nil {
		log.Panic(err)
	}

	fmt.Printf("%#v\n", req)
}

func parseForm() url.Values {
	return url.Values{
		"PostIds[]": []string{"1", "2"},
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions