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
QueryParam binding with property of uuid.UUID or uuid.NullUUID (Google) type in a struct doesn't work. Using these types in body works as expected.
uuid.UUID
uuid.NullUUID
package main import ( "fmt" "github.com/gin-gonic/gin" "github.com/gofrs/uuid" "net/http" ) func main() { r := gin.Default() r.GET("/api/test/query-params/uuid", uuidQueryParamHandler) r.GET("/api/test/query-params/null-uuid", nullUUIDQueryParamHandler) r.Run(fmt.Sprintf("localhost:%d", 8095)) } func uuidQueryParamHandler(c *gin.Context) { var model struct { ID uuid.UUID `json:"id" form:"id" binding:"uuid"` } err := c.ShouldBind(&model) if err != nil { fmt.Printf("Failed to bind query param, err: %+v\n", err) c.AbortWithError(http.StatusBadRequest, err) return } c.JSON(http.StatusOK, model) } func nullUUIDQueryParamHandler(c *gin.Context) { var model struct { ID uuid.NullUUID `json:"id" form:"id" binding:"uuid"` } err := c.ShouldBind(&model) if err != nil { fmt.Printf("Failed to bind query param, err: %+v\n", err) c.AbortWithError(http.StatusBadRequest, err) return } c.JSON(http.StatusOK, model) }
$ curl -X GET -i http://localhost:8095/api/test/query-params/uuid?id=9c018e73-449d-4a19-93bb-3a6b5ef22363 HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Date: Mon, 21 Feb 2022 11:05:58 GMT Content-Length: 45 {"id":"9c018e73-449d-4a19-93bb-3a6b5ef22363"}
$ curl -X GET -i http://localhost:8095/api/test/query-params/null-uuid?id=9c018e73-449d-4a19-93bb-3a6b5ef22363 HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8 Date: Mon, 21 Feb 2022 11:05:58 GMT Content-Length: 45 {"id":"9c018e73-449d-4a19-93bb-3a6b5ef22363"}
$ curl -X GET -i http://localhost:8095/api/test/query-params/uuid?id=9c018e73-449d-4a19-93bb-3a6b5ef22363 HTTP/1.1 400 Bad Request Date: Mon, 21 Feb 2022 10:57:46 GMT Content-Length: 0
Console log:
Error #01: ["9c018e73-449d-4a19-93bb-3a6b5ef22363"] is not valid value for uuid.UUID
$ curl -X GET -i http://localhost:8095/api/test/query-params/null-uuid?id=9c018e73-449d-4a19-93bb-3a6b5ef22363 HTTP/1.1 400 Bad Request Date: Mon, 21 Feb 2022 11:03:02 GMT Content-Length: 0
Error #01: invalid character 'c' after top-level value
The text was updated successfully, but these errors were encountered:
Duplicate of #2423
Just found it.
Sorry, something went wrong.
Duplicate of #3036
The ID's data type should be string.
ID
string
It would probably be fixed by #3045
This is still an issue. When will it be fixed in gin?
No branches or pull requests
Description
QueryParam binding with property of
uuid.UUID
oruuid.NullUUID
(Google) type in a struct doesn't work. Using these types in body works as expected.How to reproduce
Expectations
uuid.UUID
uuid.NullUUID
Actual result
uuid.UUID
Console log:
uuid.NullUUID
Console log:
Environment
The text was updated successfully, but these errors were encountered: