go get github.com/kaixinhupo/urlencode
对所有请求参数编码
package main
func test() {
params := make(map[string]string)
params["foo"]="bar"
params["local"]="**"
query := urlencode.UrlEncode(params,"gbk")
println(query)
//foo=bar&local=%d6%d0%b9%fa
}
对字符串进行编码
package main
func test() {
println(urlencode.Encode("**","gbk"))
//%d6%d0%b9%fa
}
解码
package main
func test () {
str:="foo=bar&local=%d6%d0%b9%fa"
params := urlencode.UrlDecode(str,"gbk")
fmt.Println(params)
//map[foo->bar local->**]
println(urlencode.Decode("%d6%d0%b9%fa","gbk"))
// **
}