func (l *AllowDenyList) IsIncluded(item string) bool {
	var matched bool
	for _, r := range l.rList {
		matched = r.MatchString(item)
		if matched {
			break
		}
	}
	if l.isAllowList {
		return matched
	}
	return !matched
}
IsIncluded returns if the given item is included.
package allowdenylist
import (
	"regexp"
	"strings"
	"github.com/pkg/errors"
)
type AllowDenyList struct {
	list        map[string]struct{}
	rList       []*regexp.Regexp
	isAllowList bool
}
func New(allow, deny map[string]struct{}) (*AllowDenyList, error) {
	if len(allow) != 0 && len(deny) != 0 {
		return nil, errors.New(
			"allowlist and denylist are both set, they are mutually exclusive, only one of them can be set",
		)
	}
	var list map[string]struct{}
	var isAllowList bool
	if len(allow) != 0 {
		list = copyList(allow)
		isAllowList = true
	} else {
		list = copyList(deny)
		isAllowList = false
	}
	return &AllowDenyList{
		list:        list,
		isAllowList: isAllowList,
	}, nil
}
func (l *AllowDenyList) Parse() error {
	regexes := make([]*regexp.Regexp, 0, len(l.list))
	for item := range l.list {
		r, err := regexp.Compile(item)
		if err != nil {
			return err
		}
		regexes = append(regexes, r)
	}
	l.rList = regexes
	return nil
}
func (l *AllowDenyList) Include(items []string) {
	if l.isAllowList {
		for _, item := range items {
			l.list[item] = struct{}{}
		}
	} else {
		for _, item := range items {
			delete(l.list, item)
		}
	}
}
func (l *AllowDenyList) Exclude(items []string) {
	if l.isAllowList {
		for _, item := range items {
			delete(l.list, item)
		}
	} else {
		for _, item := range items {
			l.list[item] = struct{}{}
		}
	}
}