Skip to content

Commit

Permalink
Add ExampleBuilder_ParamOptional
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Feb 24, 2024
1 parent 6be57db commit f74199f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions builder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,23 @@ func ExampleBuilder_BodyJSON() {
// ]
// }
}

func ExampleBuilder_ParamOptional() {
// Suppose we have some variables from some external source
yes := "1"
no := ""

u, err := requests.
URL("https://www.example.com/?c=something").
ParamOptional("a", yes).
ParamOptional("b", no). // Won't set ?b= because no is blank
ParamOptional("c", yes). // Won't set ?c= because it was already in the base URL
URL()
if err != nil {
fmt.Println("Error!", err)
}
fmt.Println(u.String())

// Output:
// https://www.example.com/?a=1&c=something
}

0 comments on commit f74199f

Please sign in to comment.