Skip to content

Commit 6ca134f

Browse files
committed
Add ExampleBuilder_ParamOptional
1 parent 2b66433 commit 6ca134f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

builder_example_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -706,3 +706,23 @@ func ExampleBuilder_BodyJSON() {
706706
// ]
707707
// }
708708
}
709+
710+
func ExampleBuilder_ParamOptional() {
711+
// Suppose we have some variables from some external source
712+
yes := "1"
713+
no := ""
714+
715+
u, err := requests.
716+
URL("https://www.example.com/?c=something").
717+
ParamOptional("a", yes).
718+
ParamOptional("b", no). // Won't set ?b= because no is blank
719+
ParamOptional("c", yes). // Won't set ?c= because it was already in the base URL
720+
URL()
721+
if err != nil {
722+
fmt.Println("Error!", err)
723+
}
724+
fmt.Println(u.String())
725+
726+
// Output:
727+
// https://www.example.com/?a=1&c=something
728+
}

0 commit comments

Comments
 (0)