gorilla/schema

[question] Are slices of custom types supported?

alex529 opened this issue · 4 comments

Describe the problem you're having
Hi this is more of a question as i'm not sure if it's a bug, does the package support slices of custom types?
On my first iteration of the code I used to register a custom type by with the help of RegisterConverter which worked like a charm, now i would like to support the same behaviour with a slice of custom types how is this achievable?

Versions
Go version: 1.14.1
package version: 1.2.0

"Show me the code!"
i've omitted all the details and put here only the code under question

//type
type Filter struct {
	...
	Tenure       []helpers.FloatRange  `schema:"tenure_range"` // code under question, if its not a slice it works
}

//register type
decoder.RegisterConverter(helpers.FloatRange{}, floatRangeConverter)

//converter 
func floatRangeConverter(value string) reflect.Value {
	if v, err := helpers.MakeFloatRange(value); err == nil {
		return reflect.ValueOf(v)
	}
	return reflect.Value{}
}

var f Filter
if err := c.decoder.Decode(&f, req.Form); err != nil {
	... // here the error is returned: schema: invalid path "tenure_range"
}

This PR can solve your issue.
#159

I also have the same use case as the OP and would like support for this feature.

stale commented

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

+1 for this feature, currently get schema: invalid path error