https://github.com/hetiansu5/urlquery
使用 Go 语言实现的 URL Query 字符串编码器和解码器。写好后才发现官方已有实现的querystring,但只实现了编码器,没有解码器,且只支持顶层数据结构为结构体,实现上不算特别完善。
query:"name"
)更多查看example
package main
import (
"github.com/hetiansu5/urlquery"
"fmt"
)
type SimpleChild struct {
Status bool `query:"status"`
Name string
}
type SimpleData struct {
Id int
Name string `query:"name"`
Child SimpleChild
Params map[string]int8 `query:"p"`
Array [3]uint16
}
func main() {
data := SimpleData{
Id: 2,
Name: "http://localhost/test.php?id=2",
Child: SimpleChild{
Status: true,
},
Params: map[string]int8{
"one": 1,
},
Array: [3]uint16{2, 3, 300},
}
//Marshal: from go structure to url query string
bytes, _ := urlquery.Marshal(data)
fmt.Println(string(bytes))
//Unmarshal: from url query string to go structure
v := &SimpleData{}
urlquery.Unmarshal(bytes, v)
fmt.Println(*v)