package url import ( "fmt" "net" "net/url" ) var p = fmt.Println func Url() { parsed, err := url.Parse("app://jon:password@example.org:333/path/to/secret?ref=appstore#confidential") if err != nil { panic(err) } p("Scheme:", parsed.Scheme) p("Host with Port:", parsed.Host) host, port, _ := net.SplitHostPort(parsed.Host) p("Host only:", host) p("Port only:", port) username := parsed.User.Username() password, _ := parsed.User.Password() p("Username:", username) p("Password:", password) p("Path:", parsed.Path) p("Raw query:", parsed.RawQuery) p("Fragment:", parsed.Fragment) params := parsed.Query() p("Query param 'ref':", params["ref"][0]) }