Golang: Go-QueryString encodes struct as a library for URL query parameters
This provides the lru package which implements a fixed-size thread safe LRU cache. It is based on the cache in Groupcache.
The installation
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
}