Skip to content

Commit

Permalink
validate that shard spaces have a non-empty regex
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldix committed Aug 22, 2014
1 parent c1b9a85 commit b1e6184
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions cluster/shard_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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]
}
s.compiledRegex = r
}
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
}
Expand Down

0 comments on commit b1e6184

Please sign in to comment.