go-querystring is a Go library for encoding structs into URL query parameters.
译文:go-querystring 将struct编码为URL查询参数的Golang库
文档
安装
go get github.com/google/go-querystring
示例
package main import ( "fmt" "github.com/google/go-querystring/query" ) // 注意:数据结构属性名需要大写 type Data struct { Name string `url:"name"` Age int `url:"age"` IsStudent bool `url:"isStudent"` } func main() { data := Data{ Name: "Tom", Age: 2, IsStudent: true, } value, _ := query.Values(data) output := value.Encode() fmt.Println(output) // age=2&isStudent=true&name=Tom }
参考