Golang net/url.URL.IsAbs(),Query() and RequestURI() functions example

package net/url

Golang net/url.URL.IsAbs(),Query() and RequestURI() functions usage example

 package main

 import (
  "fmt"
  "net/url"
 )

 func main() {

  rawURL := "http://username:password@searchengine.com:8080/testpath/?q=socketloop.com#TestFunc"

  parsedURL, err := url.Parse(rawURL)
  if err != nil {
 panic(err)
  }

  fmt.Println("Is absolute? : ", parsedURL.IsAbs())
  fmt.Println("Query values : ", parsedURL.Query())
  fmt.Println("Request URI : ", parsedURL.RequestURI())

 }

Output :

Is absolute? : true

Query values : map[q:[socketloop.com]]

Request URI : /testpath/?q=socketloop.com

Reference :

http://golang.org/pkg/net/url/#URL.IsAbs

http://golang.org/pkg/net/url/#URL.Query

http://golang.org/pkg/net/url/#URL.RequestURI

Advertisement