]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: add example for JoinPath
authorcuishuang <imcusg@gmail.com>
Wed, 9 Oct 2024 03:56:25 +0000 (11:56 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 10 Oct 2024 20:03:57 +0000 (20:03 +0000)
Change-Id: Ibbd2bda7ff2ea3c782ad41f6f00ad62849a4f066
Reviewed-on: https://go-review.googlesource.com/c/go/+/618756
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/net/url/example_test.go

index a1913508f72fcec18f05f736824e90b8bc942605..311ba5c329b442459434526ffffeebcbeff94942 100644 (file)
@@ -253,6 +253,18 @@ func ExampleURL_IsAbs() {
        // true
 }
 
+func ExampleURL_JoinPath() {
+       u, err := url.Parse("https://example.com/foo/bar")
+       if err != nil {
+               log.Fatal(err)
+       }
+
+       fmt.Println(u.JoinPath("baz", "qux"))
+
+       // Output:
+       // https://example.com/foo/bar/baz/qux
+}
+
 func ExampleURL_MarshalBinary() {
        u, _ := url.Parse("https://example.org")
        b, err := u.MarshalBinary()