https://github.com/knadh/querytostruct
An extremely tiny utility for unmarshalling and scanning querystrings into structs
https://github.com/knadh/querytostruct
Last synced: about 1 year ago
JSON representation
An extremely tiny utility for unmarshalling and scanning querystrings into structs
- Host: GitHub
- URL: https://github.com/knadh/querytostruct
- Owner: knadh
- License: mit
- Created: 2019-09-12T16:55:58.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-09T18:04:52.000Z (about 4 years ago)
- Last Synced: 2025-03-02T04:06:41.644Z (over 1 year ago)
- Language: Go
- Size: 3.91 KB
- Stars: 14
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# querytostruct
An extremely tiny utility for unmarshalling and scanning
querystrings into structs. It supports scanning into int*, float*, string,
and []byte types, along with []int*, []float*, and []\*string slices
## Install
`go get -u github.com/knadh/querytostruct`
## Usage
```go
package main
import (
"fmt"
"net/url"
"github.com/knadh/querytostruct"
)
func main() {
qs := "name=John+Doe&yes=true&count=42&tag=x&tag=y"
q, _ := url.ParseQuery(qs)
type test struct {
Name string `q:"name"`
Yes bool `q:"yes"`
Count int `q:"count"`
Tags []string `q:"tag"`
}
var t test
fields, err := querytostruct.Unmarshal(q, &t, "q")
fmt.Println("fields=", fields, "error=", err)
fmt.Println(t)
}
```
Licensed under the MIT License.