summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Anderson <[email protected]>2017-01-01 02:17:48 -0800
committerDavid Anderson <[email protected]>2017-01-01 02:17:48 -0800
commitb8a3ed89ade6a84297914e83559ff8cb1b7c5d33 (patch)
tree195a4d2fb474a46a475ca9c6902b280fa606c38c
parent0a0a9f658b3a5aabf24cc9c78f2ff0baef7d5622 (diff)
Add DNS name support to config
-rw-r--r--config.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/config.go b/config.go
index 0a4542b..2c0c797 100644
--- a/config.go
+++ b/config.go
@@ -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 {