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
How to add Watermark or Merge two image?
Copy an array by value and reference into another array
Example to handle GET and POST request in Golang
Select single argument from all arguments of variadic function
How to get first and last element of slice in Golang?
Regular expression to extract filename from given path in Golang