bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/name/length.go (about) 1 package name 2 3 type lengthValidationConfig struct { 4 minLen uint 5 maxLen uint 6 } 7 8 // NewLengthValidator constructs a Validator which can verify that names are of a correct length 9 func NewLengthValidator(min uint, max uint) Validator { 10 return &lengthValidationConfig{minLen: min, maxLen: max} 11 } 12 13 // IsValid returns true if the name if of an acceptable length 14 func (c *lengthValidationConfig) IsValid(name string) bool { 15 length := uint(len(name)) 16 17 return length >= c.minLen && length <= c.maxLen 18 }