7 changed files with 152 additions and 60 deletions
@ -1,54 +0,0 @@
@@ -1,54 +0,0 @@
|
||||
package conf |
||||
|
||||
import ( |
||||
"fmt" |
||||
"net" |
||||
"regexp" |
||||
) |
||||
|
||||
var rePathName = regexp.MustCompile(`^[0-9a-zA-Z_\-/]+$`) |
||||
|
||||
// CheckPathName check if a path name is valid.
|
||||
func CheckPathName(name string) error { |
||||
if name == "" { |
||||
return fmt.Errorf("cannot be empty") |
||||
} |
||||
|
||||
if name[0] == '/' { |
||||
return fmt.Errorf("can't begin with a slash") |
||||
} |
||||
|
||||
if name[len(name)-1] == '/' { |
||||
return fmt.Errorf("can't end with a slash") |
||||
} |
||||
|
||||
if !rePathName.MatchString(name) { |
||||
return fmt.Errorf("can contain only alfanumeric characters, underscore, minus or slash") |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
|
||||
func parseIPCidrList(in []string) ([]interface{}, error) { |
||||
if len(in) == 0 { |
||||
return nil, nil |
||||
} |
||||
|
||||
var ret []interface{} |
||||
for _, t := range in { |
||||
_, ipnet, err := net.ParseCIDR(t) |
||||
if err == nil { |
||||
ret = append(ret, ipnet) |
||||
continue |
||||
} |
||||
|
||||
ip := net.ParseIP(t) |
||||
if ip != nil { |
||||
ret = append(ret, ip) |
||||
continue |
||||
} |
||||
|
||||
return nil, fmt.Errorf("unable to parse ip/network '%s'", t) |
||||
} |
||||
return ret, nil |
||||
} |
||||
Loading…
Reference in new issue