1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: fix StructToUrlValues failed when tag contain omitempty

This commit is contained in:
dudaodong
2023-03-06 17:23:54 +08:00
parent a74038466f
commit ab81d9c283
6 changed files with 351 additions and 343 deletions

View File

@@ -551,22 +551,34 @@ package main
import (
"fmt"
"github.com/duke-git/lancet/netutil"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
type TodoQuery struct {
Id int `json:"id"`
UserId int `json:"userId"`
Id int `json:"id"`
UserId int `json:"userId"`
Name string `json:"name,omitempty"`
Status string
}
todoQuery := TodoQuery{
item := TodoQuery{
Id: 1,
UserId: 2,
UserId: 123,
Name: "test",
Status: "completed",
}
todoValues := netutil.StructToUrlValues(todoQuery)
queryValues := netutil.StructToUrlValues(item)
fmt.Println(todoValues.Get("id")) //1
fmt.Println(todoValues.Get("userId")) //2
fmt.Println(todoValues.Get("id"))
fmt.Println(todoValues.Get("userId"))
fmt.Println(todoValues.Get("name"))
fmt.Println(todoValues.Get("status"))
// Output:
// 1
// 123
// test
//
}
```

View File

@@ -550,22 +550,34 @@ package main
import (
"fmt"
"github.com/duke-git/lancet/netutil"
"github.com/duke-git/lancet/v2/netutil"
)
func main() {
type TodoQuery struct {
Id int `json:"id"`
UserId int `json:"userId"`
Id int `json:"id"`
UserId int `json:"userId"`
Name string `json:"name,omitempty"`
Status string
}
todoQuery := TodoQuery{
item := TodoQuery{
Id: 1,
UserId: 2,
UserId: 123,
Name: "test",
Status: "completed",
}
todoValues := netutil.StructToUrlValues(todoQuery)
queryValues := netutil.StructToUrlValues(item)
fmt.Println(todoValues.Get("id")) //1
fmt.Println(todoValues.Get("userId")) //2
fmt.Println(todoValues.Get("id"))
fmt.Println(todoValues.Get("userId"))
fmt.Println(todoValues.Get("name"))
fmt.Println(todoValues.Get("status"))
// Output:
// 1
// 123
// test
//
}
```