github.com/icyphox/x@v0.0.355-0.20220311094250-029bd783e8b8/urlx/copy.go (about)

     1  package urlx
     2  
     3  import "net/url"
     4  
     5  // Copy returns a copy of the input url.
     6  func Copy(src *url.URL) *url.URL {
     7  	var out = new(url.URL)
     8  	*out = *src
     9  	return out
    10  }
    11  
    12  // CopyWithQuery returns a copy of the input url with the given query parameters
    13  func CopyWithQuery(src *url.URL, query url.Values) *url.URL {
    14  	out := Copy(src)
    15  	q := out.Query()
    16  	for k := range query {
    17  		q.Set(k, query.Get(k))
    18  	}
    19  	out.RawQuery = q.Encode()
    20  	return out
    21  }