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