validate that shard spaces have a non-empty regex

pull/875/head v0.8.0
Paul Dix 2014-08-22 15:01:03 -04:00
parent c1b9a85305
commit b1e6184ea1
1 changed files with 15 additions and 14 deletions

View File

@ -56,21 +56,22 @@ func (s *ShardSpace) Validate(clusterConfig *ClusterConfiguration, checkForDb bo
if s.Name == "" {
return fmt.Errorf("Shard space must have a name")
}
if s.Regex != "" {
reg := s.Regex
if strings.HasPrefix(reg, "/") {
if strings.HasSuffix(reg, "/i") {
reg = fmt.Sprintf("(?i)%s", reg[1:len(reg)-2])
} else {
reg = reg[1 : len(reg)-1]
}
}
r, err := regexp.Compile(reg)
if err != nil {
return fmt.Errorf("Error parsing regex: %s", err)
}
s.compiledRegex = r
if s.Regex == "" {
return fmt.Errorf("A regex is required for a shard space")
}
reg := s.Regex
if strings.HasPrefix(reg, "/") {
if strings.HasSuffix(reg, "/i") {
reg = fmt.Sprintf("(?i)%s", reg[1:len(reg)-2])
} else {
reg = reg[1 : len(reg)-1]
}
}
r, err := regexp.Compile(reg)
if err != nil {
return fmt.Errorf("Error parsing regex: %s", err)
}
s.compiledRegex = r
if s.Split == 0 {
s.Split = DEFAULT_SPLIT
}