Golang net/url.ParseQuery() and Get() functions example

package net/url

Golang net/url.ParseQuery() and Get() functions usage example

 package main

 import (
  "fmt"
  "net/url"
 )

 func main() {

  // username and password must be in plain text (see below)
  rawURL := "http://username:password@searchengine.com:8080/testpath/?q=socketloop.com#TestFunc"

  val, err := url.ParseQuery(rawURL)

  if err != nil {
 panic(err)
  }

  fmt.Println(val.Get("http://username:password@searchengine.com:8080/testpath/?q"))

 }

Output :

socketloop.com#TestFunc

References :

http://golang.org/pkg/net/url/#ParseQuery

http://golang.org/pkg/net/url/#Values.Get

Advertisement