Standard library / net/url

url.URL.ResolveReference()

Resolve a URL reference without mutating the base. Expected stdout: 'https://example.invalid/new?q=2\n'.

Formal Syntax & Structure

go syntaxgo
func (u *URL) ResolveReference(ref *URL) *URL

Parameters & Attributes

NameTypeDescription
ref*URLRelative or absolute reference to resolve.

Return Value

*URL

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/url")
func main() {  u := must(url.Parse("https://example.invalid/a%2Fb?q=go#x%20y"))  fmt.Println(u.ResolveReference(must(url.Parse("/new?q=2"))))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference