|
| 1 | +Hyperscale InputFilter [](https://github.com/hyperscale-stack/inputfilter/releases/latest) [](https://godoc.org/github.com/hyperscale-stack/inputfilter) |
| 2 | +==================== |
| 3 | + |
| 4 | +[](https://goreportcard.com/report/github.com/hyperscale-stack/inputfilter) |
| 5 | + |
| 6 | +| Branch | Status | Coverage | |
| 7 | +|---------|--------|----------| |
| 8 | +| master | [](https://github.com/hyperscale-stack/inputfilter/actions?query=workflow%3AGo) | [](https://coveralls.io/github/hyperscale-stack/inputfilter?branch=master) | |
| 9 | + |
| 10 | +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. |
| 11 | + |
| 12 | +## Example |
| 13 | + |
| 14 | +Filter by `map[string]interface{}` |
| 15 | + |
| 16 | +```go |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/hyperscale-stack/filter" |
| 23 | + "github.com/hyperscale-stack/validator" |
| 24 | + "github.com/hyperscale-stack/inputfilter" |
| 25 | +) |
| 26 | + |
| 27 | +func main() { |
| 28 | + i := New(map[string]InputDefinition{ |
| 29 | + "*": { |
| 30 | + Filters: []filter.Filter{ |
| 31 | + filter.NewStringToLowerFilter(), |
| 32 | + }, |
| 33 | + }, |
| 34 | + "url": { |
| 35 | + Filters: []filter.Filter{ |
| 36 | + filter.NewURLFilter(), |
| 37 | + }, |
| 38 | + }, |
| 39 | + "id": { |
| 40 | + Validators: []validator.Validator{ |
| 41 | + validator.NewUUIDValidator(), |
| 42 | + }, |
| 43 | + }, |
| 44 | + }) |
| 45 | + |
| 46 | + data, errs := i.FilterMap(map[string]interface{}{ |
| 47 | + "id": "9D2C8507-5F9D-4CB0-A098-2E307B39DC91", |
| 48 | + "url": "HTTPS://google.COM", |
| 49 | + }) |
| 50 | + // return |
| 51 | + // map[string]interface{}{ |
| 52 | + // "id": "9d2c8507-5f9d-4cb0-a098-2e307b39dc91", |
| 53 | + // "url": "https://google.com", |
| 54 | + // } |
| 55 | +} |
| 56 | + |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | +Filter by `url.Values` |
| 61 | + |
| 62 | +```go |
| 63 | +package main |
| 64 | + |
| 65 | +import ( |
| 66 | + "fmt" |
| 67 | + |
| 68 | + "github.com/hyperscale-stack/filter" |
| 69 | + "github.com/hyperscale-stack/validator" |
| 70 | + "github.com/hyperscale-stack/inputfilter" |
| 71 | +) |
| 72 | + |
| 73 | +func main() { |
| 74 | + i := New(map[string]InputDefinition{ |
| 75 | + "*": { |
| 76 | + Filters: []filter.Filter{ |
| 77 | + filter.NewStringToLowerFilter(), |
| 78 | + }, |
| 79 | + }, |
| 80 | + "url": { |
| 81 | + Filters: []filter.Filter{ |
| 82 | + filter.NewURLFilter(), |
| 83 | + }, |
| 84 | + }, |
| 85 | + "id": { |
| 86 | + Validators: []validator.Validator{ |
| 87 | + validator.NewUUIDValidator(), |
| 88 | + }, |
| 89 | + }, |
| 90 | + }) |
| 91 | + |
| 92 | + values := url.Values{} |
| 93 | + values.Set("id", "9D2C8507-5F9D-4CB0-A098-2E307B39DC91") |
| 94 | + values.Set("url", "HTTPS://google.COM") |
| 95 | + |
| 96 | + data, errs := i.FilterValues(values) |
| 97 | + // return |
| 98 | + // url.Values{ |
| 99 | + // "id": []string{"9d2c8507-5f9d-4cb0-a098-2e307b39dc91"}, |
| 100 | + // "url": []string{"https://google.com"}, |
| 101 | + // } |
| 102 | +} |
| 103 | + |
| 104 | +``` |
| 105 | + |
| 106 | + |
| 107 | +## License |
| 108 | + |
| 109 | +Hyperscale Filter is licensed under [the MIT license](LICENSE.md). |
0 commit comments