Skip to content

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.

License

Notifications You must be signed in to change notification settings

hyperscale-stack/inputfilter

Repository files navigation

Hyperscale InputFilter Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

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.

Example

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"},
    // }
}

License

Hyperscale Filter is licensed under the MIT license.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published