Skip to content

proposal: net/url: add URL.Clone method #41733

Closed
@icholy

Description

@icholy

Copying a url is often done by shallow copying the struct. This can be confusing because it's not clear if the Userinfo should also be copied.

u, _ := url.Parse("http://foo")

// shallow copy the struct
u2 := *u

Another option is to format/re-parse the url. But this adds unnecessary overhead.

u2, _ := url.Parse(u.String())

Given how often url cloning comes up, I think it warrants adding a helper.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions