diff options
author | David Anderson <[email protected]> | 2017-01-01 02:17:48 -0800 |
---|---|---|
committer | David Anderson <[email protected]> | 2017-01-01 02:17:48 -0800 |
commit | b8a3ed89ade6a84297914e83559ff8cb1b7c5d33 (patch) | |
tree | 195a4d2fb474a46a475ca9c6902b280fa606c38c | |
parent | 0a0a9f658b3a5aabf24cc9c78f2ff0baef7d5622 (diff) |
Add DNS name support to config
-rw-r--r-- | config.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -36,7 +36,22 @@ type Config struct { } func dnsRegex(s string) (*regexp.Regexp, error) { - return regexp.Compile(s) + if len(s) >= 2 && s[0] == '/' && s[len(s)-1] == '/' { + return regexp.Compile(s[1 : len(s)-1]) + } + + var b []string + for _, f := range strings.Split(s, ".") { + switch f { + case "*": + b = append(b, `[^.]+`) + case "": + return nil, fmt.Errorf("DNS name %q has empty label", s) + default: + b = append(b, regexp.QuoteMeta(f)) + } + } + return regexp.Compile(strings.Join(b, `\.`)) } func (c *Config) Match(hostname string) string { |