1
0
Fork 0
mirror of https://github.com/Luzifer/named-blacklist.git synced 2024-11-08 07:20:07 +00:00

Make comments sortable for diffing generated files

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-02-15 14:22:35 +01:00
parent 09170e8f8d
commit b565234570
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
6 changed files with 14 additions and 9 deletions

View file

@ -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").

View file

@ -114,7 +114,7 @@ template: |
; Blacklist entries
{{ range .blacklist -}}
{{ to_punycode .Domain }} CNAME . ; {{ .Comment }}
{{ to_punycode .Domain }} CNAME . ; {{ .Comments }}
{{ end }}
...

View file

@ -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
}
}

View file

@ -12,8 +12,8 @@ var (
)
type entry struct {
Domain string
Comment string
Domain string
Comments []string
}
type provider interface {

View file

@ -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},
})
}

View file

@ -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},
})
}