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
Simple function with return value in Golang
How to create thumbnail of an image?
What is GOPATH?
Find element in a slice and move it to first position?
Regular expression to extract domain from URL
How to check UPPERCASE characters in a string in Golang?
Golang Read Write Create and Delete text file
Normal function parameter with variadic function parameter
How to concatenate two or more slices in Golang?
How to read names of all files and folders in current directory?