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 } 22