We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support UnmarshalParam for custom string slice type in tag form.
If we define a custom type of string slice and implement the Gin's interface of UnmarshalParam, then we can't get the expected result.
package main import ( "fmt" "net/http" "strings" "github.com/gin-gonic/gin" ) type CustomPath []string func (b *CustomPath) UnmarshalParam(param string) error { elems := strings.Split(param, "/") n := len(elems) if n < 2 { return fmt.Errorf("invalid path: %s", param) } *b = elems return nil } type PathRequest struct { Paths CustomPath `form:"path"` } func main() { g := gin.Default() g.GET("", func(c *gin.Context) { var request PathRequest if err := c.ShouldBind(&request); err != nil { c.String(http.StatusBadRequest, "request parse err: %v", err) return } c.String(200, "Hello %s", request.Paths) }) g.Run(":9000") }
$ curl 'http://127.0.0.1:9000?path=hello/world' CustomPath: [hello world]
$ curl 'http://127.0.0.1:9000?path=hello/world' CustomPath: [hello/world]
The text was updated successfully, but these errors were encountered:
feat(form): add custom string slice for form tag unmarshal (gin-gonic…
6c9ca3d
…#3970)
e0fa1ef
5e4591f
feat(form): add custom string slice for form tag unmarshal (#3970) (#…
24d6764
…3971) Co-authored-by: Bruce Lee <admin@ifocusad.com>
Successfully merging a pull request may close this issue.
Feature
Support UnmarshalParam for custom string slice type in tag form.
Description
If we define a custom type of string slice and implement the Gin's interface of UnmarshalParam, then we can't get the expected result.
How to reproduce
Expectations
Actual result
Environment
The text was updated successfully, but these errors were encountered: