需要引入包:github.com/dora-go/query-parser
示例代码:
type pData struct { A string `schema:"a"` B string `schema:"b"` } func main() { urlPath := "https://ijackey.com/?a=a&b=b" data, _ := url.Parse(urlPath) m, _ := url.ParseQuery(data.RawQuery) s := &pData{} decoder := schema.NewDecoder() _ = decoder.Decode(s, m) fmt.Println(s.A) }