forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
579 B
25 lines
579 B
package pattern
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var patternReString = `^[A-z0-9_\-/=.:*]*$`
|
|
var patternRe = regexp.MustCompile(patternReString)
|
|
|
|
var maxPatternLength = 160
|
|
|
|
func Valid(pattern string) (bool, string) {
|
|
if strings.HasPrefix(pattern, "/") {
|
|
return false, "pattern can't start with /"
|
|
}
|
|
if !patternRe.MatchString(pattern) {
|
|
return false, fmt.Sprintf("pattern format error, must match %s", patternReString)
|
|
}
|
|
if len(pattern) > maxPatternLength {
|
|
return false, fmt.Sprintf("pattern max length exceeded (%d)", maxPatternLength)
|
|
}
|
|
return true, ""
|
|
}
|
|
|