6
Golang:go-querystring将struct编码为URL查询参数的库
source link: https://blog.51cto.com/u_13567403/5652359
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Golang:go-querystring将struct编码为URL查询参数的库
精选 原创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
}
- 打赏
- 赞
- 收藏
- 评论
- 分享
- 举报
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK