1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 07:42:27 +08:00

fix: fix StructToUrlValues failed when tag contain omitempty

This commit is contained in:
dudaodong
2023-03-06 17:07:57 +08:00
parent 71aa91a58d
commit 6a9eb645bb
5 changed files with 84 additions and 42 deletions

View File

@@ -123,21 +123,42 @@ func ExampleHttpClient_DecodeResponse() {
func ExampleStructToUrlValues() {
type TodoQuery struct {
Id int `json:"id"`
Name string `json:"name"`
Id int `json:"id"`
UserId int `json:"userId"`
Name string `json:"name,omitempty"`
Status string
}
todoQuery := TodoQuery{
Id: 1,
Name: "Test",
item1 := TodoQuery{
Id: 1,
UserId: 123,
Name: "test",
Status: "completed",
}
todoValues := StructToUrlValues(todoQuery)
queryValues1 := StructToUrlValues(item1)
fmt.Println(todoValues.Get("id"))
fmt.Println(todoValues.Get("name"))
item2 := TodoQuery{
Id: 2,
UserId: 456,
}
queryValues2 := StructToUrlValues(item2)
fmt.Println(queryValues1.Get("id"))
fmt.Println(queryValues1.Get("userId"))
fmt.Println(queryValues1.Get("name"))
fmt.Println(queryValues1.Get("status"))
fmt.Println(queryValues2.Get("id"))
fmt.Println(queryValues2.Get("userId"))
fmt.Println(queryValues2.Get("name"))
// Output:
// 1
// Test
// 123
// test
//
// 2
// 456
//
}
func ExampleConvertMapToQueryString() {