https://github.com/powerman/urlvalues
Go package for unmarshaling url.Values to struct with strict validation
https://github.com/powerman/urlvalues
Last synced: 11 months ago
JSON representation
Go package for unmarshaling url.Values to struct with strict validation
- Host: GitHub
- URL: https://github.com/powerman/urlvalues
- Owner: powerman
- License: mit
- Created: 2018-04-06T20:50:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-28T22:16:47.000Z (about 4 years ago)
- Last Synced: 2025-02-15T05:52:37.301Z (11 months ago)
- Language: Go
- Size: 176 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# urlvalues [](http://godoc.org/github.com/powerman/urlvalues) [](https://goreportcard.com/report/github.com/powerman/urlvalues) [](https://circleci.com/gh/powerman/urlvalues) [](https://coveralls.io/github/powerman/urlvalues?branch=master)
Go package for strict decoding of url.Values to given struct.
**WARNING:** This package is experimental, API will change!
## Strict validation rules
- (optional) error on unknown param
- including param matching real, but not qualified enough field name:
- struct without .field (TODO in case custom handler not registered)
- map without [key]
- error on array overflow
- array with out-of-bound [index]
- too many params for array field
- error on scalar overflow
- multiple values for non-slice/array field
- multiple values for same `array[index]` or `map[key]` (in case this
array/map doesn't have values of slice/array type)
- error on no values for non-pointer/slice/array field tagged
`form:"…,required"`
- panic on unknown `form:""` tag option
## Benchmark
- `Small`/`Large` means size of struct.
- `Failure` means failed strict validation and skipped `form.Decoder.Decode()`.
- `Loose` means without strict validation, i.e. just `form.Decoder.Decode()`.
```
BenchmarkSmallFailure 1000000 1224 ns/op 944 B/op 10 allocs/op
BenchmarkSmallSuccess 1000000 1540 ns/op 592 B/op 9 allocs/op
BenchmarkSmallSuccessLoose 3000000 524 ns/op 448 B/op 5 allocs/op
BenchmarkLargeFailure 50000 33754 ns/op 5557 B/op 45 allocs/op
BenchmarkLargeSuccess 10000 419697 ns/op 817797 B/op 77 allocs/op
BenchmarkLargeSuccessLoose 10000 381430 ns/op 814318 B/op 50 allocs/op
```