Description
Proposal Details
Proposed addition:
// Clone returns a copy of u
func (u *URL) Clone() *URL
// Clone returns a copy of v
func (v Values) Clone() Values
Motivation
Right now, there's no clear way to safely copy a net/url.URL: #38351
As the linked issue states, it is safe to do url2 := *url1
, but it's not clear to users.
For example a rough (String/Parse are common names, so guestimate with u
) search shows:
- 21.2k hits for url2 = *url1: https://github.com/search?q=language%3Ago+%2F%28.*%29u%28rl%29%3F+%3A%3F%3D+%5C*%28.*%29u%28rl%29%3F%2F&type=code
- 3.3k hits for url2, _ = url.Parse(url1.String()): https://github.com/search?q=language%3Ago+%2Furl%5C.Parse%5C%28.*u%28rl%29%3F.%5CString%5C%28%5C%29%5C%29%2F&type=code
That is a significant portion (1/8) of users paying the additional cost of serialization/deserialization for what could be a simple copy.
The parse variant also means having to deal with an error return variable that should always be nil.
The safe and efficient way of doing it should be:
Line 41 in 49860cf
For Values, because of its nested map[string][]string
structure, a deep clone is necessary (and not possible with . While it is less common than a url's Parse(u.String()), I think it should be available:
Metadata
Metadata
Assignees
Labels
Type
Projects
Status