-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse.go
47 lines (36 loc) · 987 Bytes
/
parse.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"strings"
)
func parseDomainName(domainName string, sftab serfFilterTable) serfFilter {
customDomainNameExist := checkCustomDomainNameExistence(domainName, sftab)
if customDomainNameExist {
return parseCustomDomainName(domainName, sftab)
}
return parseTagsDomainName(domainName)
}
func parseTagsDomainName(domainName string) serfFilter {
domainName = strings.TrimSuffix(domainName, *configDomainName)
tags := make(map[string]string)
for domainName != "" {
tagValue, tagName, remain := findTag(domainName)
tags[tagName] = tagValue
domainName = remain
}
sf := serfFilter{
Name: "",
Status: "alive",
Tags: tags,
}
return sf
}
func findTag(domainName string) (tagValue, tagName, remain string) {
if domainName == "" {
return "", "", ""
}
res := strings.SplitN(domainName, ".", 3)
return res[0], res[1], res[2]
}
func parseCustomDomainName(domainName string, sftab serfFilterTable) serfFilter {
return sftab[domainName]
}