ValidateContextName checks a context name is valid.
(name string)
| 214 | |
| 215 | // ValidateContextName checks a context name is valid. |
| 216 | func ValidateContextName(name string) error { |
| 217 | if name == "" { |
| 218 | return errors.New("context name cannot be empty") |
| 219 | } |
| 220 | if name == "default" { |
| 221 | return errors.New(`"default" is a reserved context name`) |
| 222 | } |
| 223 | if !isValidName(name) { |
| 224 | return fmt.Errorf("context name %q is invalid, names are validated against regexp %q", name, validNameFormat) |
| 225 | } |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | // validNameFormat is used as part of errors for invalid context-names. |
| 230 | // We should consider making this less technical ("must start with "a-z", |
searching dependent graphs…