]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: implement encoding.BinaryAppender for URL
authorapocelipes <seve3r@outlook.com>
Wed, 7 Aug 2024 23:35:23 +0000 (23:35 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 8 Aug 2024 19:43:18 +0000 (19:43 +0000)
For #62384

Change-Id: I61529efe3a59b13606479b74af6cbff61c9efb6e
GitHub-Last-Rev: f188b91978711c55aa2daf2c72277990d25bc328
GitHub-Pull-Request: golang/go#68763
Reviewed-on: https://go-review.googlesource.com/c/go/+/603815
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>

api/next/62384.txt
doc/next/6-stdlib/99-minor/net/url/62384.md [new file with mode: 0644]
src/net/url/url.go
src/net/url/url_test.go

index c8dc0c8350cb426d9b006e5c00a44e5e510dd46b..37e0080a139ace1777efbacb29fc2127ec9005b7 100644 (file)
@@ -2,3 +2,4 @@ pkg encoding, type BinaryAppender interface { AppendBinary } #62384
 pkg encoding, type BinaryAppender interface, AppendBinary([]uint8) ([]uint8, error) #62384
 pkg encoding, type TextAppender interface { AppendText } #62384
 pkg encoding, type TextAppender interface, AppendText([]uint8) ([]uint8, error) #62384
+pkg net/url, method (*URL) AppendBinary([]uint8) ([]uint8, error) #62384
diff --git a/doc/next/6-stdlib/99-minor/net/url/62384.md b/doc/next/6-stdlib/99-minor/net/url/62384.md
new file mode 100644 (file)
index 0000000..1d75943
--- /dev/null
@@ -0,0 +1 @@
+[URL] now also implements the [encoding.BinaryAppender] interface.
index 7beaef1ba66311419864d2f86b4eb39d9524ed83..9af192fa1f29de36cce22fc009b9827bb819824c 100644 (file)
@@ -1219,7 +1219,11 @@ func splitHostPort(hostPort string) (host, port string) {
 // Would like to implement MarshalText/UnmarshalText but that will change the JSON representation of URLs.
 
 func (u *URL) MarshalBinary() (text []byte, err error) {
-       return []byte(u.String()), nil
+       return u.AppendBinary(nil)
+}
+
+func (u *URL) AppendBinary(b []byte) ([]byte, error) {
+       return append(b, u.String()...), nil
 }
 
 func (u *URL) UnmarshalBinary(text []byte) error {
index 68219c3df1081d6aa792cbb86ef5999a21e8edc8..16e08b63c6d09868a7e0f6ce66b49174f982a350 100644 (file)
@@ -1866,6 +1866,7 @@ func TestURLHostnameAndPort(t *testing.T) {
 
 var _ encodingPkg.BinaryMarshaler = (*URL)(nil)
 var _ encodingPkg.BinaryUnmarshaler = (*URL)(nil)
+var _ encodingPkg.BinaryAppender = (*URL)(nil)
 
 func TestJSON(t *testing.T) {
        u, err := Parse("https://www.google.com/x?y=z")