diff --git a/config.go b/config.go index f69a76d..ae5862c 100644 --- a/config.go +++ b/config.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "net/http" "os" + "sort" "strings" "text/template" @@ -86,6 +87,11 @@ func loadConfigFile(filename string) (*configfile, error) { funcs := korvike.GetFunctionMap() funcs["to_punycode"] = domainToPunycode + funcs["join"] = strings.Join + funcs["sort"] = func(in []string) []string { + sort.Slice(in, func(i, j int) bool { return strings.ToLower(in[i]) < strings.ToLower(in[j]) }) + return in + } if out.tpl, err = template. New("configTemplate"). diff --git a/config.sample.yaml b/config.sample.yaml index f62bcd9..5709e37 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -114,7 +114,7 @@ template: | ; Blacklist entries {{ range .blacklist -}} - {{ to_punycode .Domain }} CNAME . ; {{ .Comment }} + {{ to_punycode .Domain }} CNAME . ; {{ .Comments }} {{ end }} ... diff --git a/main.go b/main.go index ed766a3..8cc6d45 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "fmt" "os" "sort" - "strings" "sync" log "github.com/sirupsen/logrus" @@ -108,7 +107,7 @@ func main() { func addIfNotExists(entries []entry, e entry) []entry { for i, pe := range entries { if pe.Domain == e.Domain { - entries[i].Comment = strings.Join([]string{pe.Comment, e.Comment}, ", ") + entries[i].Comments = append(pe.Comments, e.Comments...) return entries } } diff --git a/provider.go b/provider.go index 938328e..31953f9 100644 --- a/provider.go +++ b/provider.go @@ -12,8 +12,8 @@ var ( ) type entry struct { - Domain string - Comment string + Domain string + Comments []string } type provider interface { diff --git a/provider_domainList.go b/provider_domainList.go index 51f7215..8d69e12 100644 --- a/provider_domainList.go +++ b/provider_domainList.go @@ -44,8 +44,8 @@ func (p providerdomainList) GetDomainList(d providerDefinition) ([]entry, error) } entries = append(entries, entry{ - Domain: domain, - Comment: d.Name, + Domain: domain, + Comments: []string{d.Name}, }) } diff --git a/provider_hostFile.go b/provider_hostFile.go index 20761fa..c28b839 100644 --- a/provider_hostFile.go +++ b/provider_hostFile.go @@ -63,8 +63,8 @@ func (p providerHostFile) GetDomainList(d providerDefinition) ([]entry, error) { } entries = append(entries, entry{ - Domain: groups[1], - Comment: comment, + Domain: groups[1], + Comments: []string{comment}, }) }