2018-02-05 16:05:59 -05:00
|
|
|
package discovery // import "github.com/docker/docker/pkg/discovery"
|
2015-08-31 16:23:17 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Generate takes care of IP generation
|
|
|
|
func Generate(pattern string) []string {
|
|
|
|
re, _ := regexp.Compile(`\[(.+):(.+)\]`)
|
|
|
|
submatch := re.FindStringSubmatch(pattern)
|
|
|
|
if submatch == nil {
|
|
|
|
return []string{pattern}
|
|
|
|
}
|
|
|
|
|
|
|
|
from, err := strconv.Atoi(submatch[1])
|
|
|
|
if err != nil {
|
|
|
|
return []string{pattern}
|
|
|
|
}
|
|
|
|
to, err := strconv.Atoi(submatch[2])
|
|
|
|
if err != nil {
|
|
|
|
return []string{pattern}
|
|
|
|
}
|
|
|
|
|
|
|
|
template := re.ReplaceAllString(pattern, "%d")
|
|
|
|
|
|
|
|
var result []string
|
|
|
|
for val := from; val <= to; val++ {
|
|
|
|
entry := fmt.Sprintf(template, val)
|
|
|
|
result = append(result, entry)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|