Branch | Status | Coverage |
---|---|---|
master |
The Hyperscale InputFilter library provides a simple inputfilter chaining mechanism by which multiple filters and validator may be applied to a single datum in a user-defined order.
Filter by map[string]interface{}
package main
import (
"fmt"
"github.com/hyperscale-stack/filter"
"github.com/hyperscale-stack/validator"
"github.com/hyperscale-stack/inputfilter"
)
func main() {
i := New(map[string]InputDefinition{
"*": {
Filters: []filter.Filter{
filter.NewStringToLowerFilter(),
},
},
"url": {
Filters: []filter.Filter{
filter.NewURLFilter(),
},
},
"id": {
Validators: []validator.Validator{
validator.NewUUIDValidator(),
},
},
})
data, errs := i.FilterMap(map[string]interface{}{
"id": "9D2C8507-5F9D-4CB0-A098-2E307B39DC91",
"url": "HTTPS://google.COM",
})
// return
// map[string]interface{}{
// "id": "9d2c8507-5f9d-4cb0-a098-2e307b39dc91",
// "url": "https://google.com",
// }
}
Filter by url.Values
package main
import (
"fmt"
"github.com/hyperscale-stack/filter"
"github.com/hyperscale-stack/validator"
"github.com/hyperscale-stack/inputfilter"
)
func main() {
i := New(map[string]InputDefinition{
"*": {
Filters: []filter.Filter{
filter.NewStringToLowerFilter(),
},
},
"url": {
Filters: []filter.Filter{
filter.NewURLFilter(),
},
},
"id": {
Validators: []validator.Validator{
validator.NewUUIDValidator(),
},
},
})
values := url.Values{}
values.Set("id", "9D2C8507-5F9D-4CB0-A098-2E307B39DC91")
values.Set("url", "HTTPS://google.COM")
data, errs := i.FilterValues(values)
// return
// url.Values{
// "id": []string{"9d2c8507-5f9d-4cb0-a098-2e307b39dc91"},
// "url": []string{"https://google.com"},
// }
}
Hyperscale Filter is licensed under the MIT license.