go - net/url package: strip query from url -
i wanted make sure wasn't missing on net/url package. there way url without query, without using using strings package strip out?
package main import ( "fmt" "net/url" ) func main() { u, _ := url.parse("/url?foo=bar&foo=baz") fmt.printf("full uri: %#v\n", u.string()) fmt.printf("query: %#v", u.query()) }
i not sure if asking can use u.path
attribute path of url or of attributes specified url
type url struct { scheme string opaque string // encoded opaque data user *userinfo // username , password information host string // host or host:port path string rawquery string // encoded query values, without '?' fragment string // fragment references, without '#' } // scheme://[userinfo@]host/path[?query][#fragment]
example:
package main import ( "fmt" "net/url" ) func main() { u, _ := url.parse("http://www.test.com/url?foo=bar&foo=baz#this_is_fragment") fmt.println("full uri:", u.string()) fmt.println("scheme:", u.scheme) fmt.println("opaque:", u.opaque) fmt.println("host:", u.host) fmt.println("path", u.path) fmt.println("fragment", u.fragment) fmt.println("rawquery", u.rawquery) fmt.printf("query: %#v", u.query()) }
Comments
Post a Comment