-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdns.go
More file actions
34 lines (25 loc) · 819 Bytes
/
dns.go
File metadata and controls
34 lines (25 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package coredns_omada
import (
"regexp"
"strings"
)
func makeDNSSafe(input string) string {
// Replace any whitespace with hyphens
input = strings.Replace(input, " ", "-", -1)
// Remove any characters that are not letters, numbers, or hyphens
re := regexp.MustCompile("[^a-zA-Z0-9-]")
input = re.ReplaceAllString(input, "")
// Convert the string to lower case
input = strings.ToLower(input)
return input
}
func makeDNSSafeAllowWildcard(input string) string {
// Replace any whitespace with hyphens
input = strings.Replace(input, " ", "-", -1)
// Remove any characters that are not letters, numbers, hypens, wildcards or dots
re := regexp.MustCompile(`[^a-zA-Z0-9-\*\.]`)
input = re.ReplaceAllString(input, "")
// Convert the string to lower case
input = strings.ToLower(input)
return input
}