Split URL and Get Parameters from URL
Example
package main
import (
"bufio"
"encoding/hex"
"fmt"
"os"
"strings"
)
func main() {
fmt.Println("Enter your url here:")
url := bufio.NewReader(os.Stdin)
line, _ := url.ReadString('\n')
paramStr := strings.Split(line, "?")[1]
params := strings.Split(paramStr, "&")
print("\n")
for _, param := range params {
percentSpl := strings.Split(param, "%")
var strPara string
if len(percentSpl) > 1 {
for i, j := range percentSpl {
if i == 0 {
strPara += j
} else {
bl, _ := hex.DecodeString(j[:2])
strung := string(bl)
strPara += strung
strPara += j[2:]
}
}
} else {
strPara = param
}
fmt.Println(strPara)
}
}
Output
Enter your url here:
http://www.golangprograms.com/catalogsearch/result/?q=Examples%20and%20Solutions&is_v=1
q=Examples and Solutions
is_v=1
Most Helpful This Week
Sierpinski triangle in Go Programming Language
Regular expression to validate the date format in "dd/mm/yyyy"
How to set timeout for http.Get() requests in Golang?
How to update content of a text file?
Example: How to use ReadFull from IO Package in Golang?
Find out how many logical processors used by current process
How to split a string on white-space?
How to check string contains uppercase lowercase character in Golang?
Split a string at uppercase letters using regular expression in Golang
The return values of a function can be named in Golang