43 lines
889 B
Go
43 lines
889 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
type MatcherPredicateType uint8
|
|
|
|
const (
|
|
MatcherPredicateTypeUnknown MatcherPredicateType = iota
|
|
MatcherPredicateTypePattern
|
|
MatcherPredicateTypeRegexp
|
|
)
|
|
|
|
func (t *MatcherPredicateType) UnmarshalText(data []byte) error {
|
|
switch dataStr := strings.ToLower(string(data)); dataStr {
|
|
case "":
|
|
*t = MatcherPredicateTypeUnknown
|
|
case "pattern":
|
|
*t = MatcherPredicateTypePattern
|
|
case "regexp":
|
|
*t = MatcherPredicateTypeRegexp
|
|
default:
|
|
return errors.New("unsupported type " + dataStr)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
type MatcherPredicate struct {
|
|
Value string `toml:"value"`
|
|
Type MatcherPredicateType `toml:"type"`
|
|
}
|
|
|
|
type DimensionMatcher struct {
|
|
CaseInsensitive bool `toml:"case_insensitive"`
|
|
|
|
Length []MatcherPredicate `toml:"length"`
|
|
Width []MatcherPredicate `toml:"width"`
|
|
Height []MatcherPredicate `toml:"height"`
|
|
}
|