https://github.com/wgarunap/url-query-binder
http request url query parameters bind into struct
https://github.com/wgarunap/url-query-binder
Last synced: about 1 month ago
JSON representation
http request url query parameters bind into struct
- Host: GitHub
- URL: https://github.com/wgarunap/url-query-binder
- Owner: wgarunap
- License: mit
- Created: 2021-03-17T09:06:39.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-17T09:24:23.000Z (about 4 years ago)
- Last Synced: 2023-03-07T14:33:26.005Z (about 2 years ago)
- Language: Go
- Size: 1.95 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
# Go URL Query Binder
Simple, yet Powerful library. This library binds the URL request query parameters to Go structs based on the given tag key.### How to use
Add dependency to your repository
```shell
go get -u github.com/wgarunap/url-query-binder
```
Import dependency to your code
```shell
import querybinder "github.com/wgarunap/url-query-binder"
```### Example
```go
type Obj struct {
Query string `bind:"query,required"`
StringParam string `bind:"string_param"`
SliceParam []string `bind:"slice_param"`
IntParam int `bind:"int_param"`
}func main() {
var obj Obj
u, _ := url.Parse("/get?query=something&string_param=testing&slice_param=param1&slice_param=param2&int_param=12")qb := querybinder.NewQueryBinder()
_ = qb.Bind(&obj, u)log.Println(obj.Query)
log.Println(obj.StringParam)
log.Println(obj.SliceParam)
log.Println(obj.IntParam)
}
```##### Output
```shell
something
testing
[param1 param2]
12
```### Benchmark
Benchmark was done with 4 query parameters and results as below.```bash
goos: darwin
goarch: amd64
pkg: github.com/wgarunap/url-query-binder
cpu: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
BenchmarkBinderBind-4 581227 2125 ns/op
PASS
ok github.com/wgarunap/url-query-binder 2.320s```
## Contributions
Contributions are welcome :)