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:
parent
09170e8f8d
commit
b565234570
6 changed files with 14 additions and 9 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
|
@ -86,6 +87,11 @@ func loadConfigFile(filename string) (*configfile, error) {
|
||||||
|
|
||||||
funcs := korvike.GetFunctionMap()
|
funcs := korvike.GetFunctionMap()
|
||||||
funcs["to_punycode"] = domainToPunycode
|
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.
|
if out.tpl, err = template.
|
||||||
New("configTemplate").
|
New("configTemplate").
|
||||||
|
|
|
@ -114,7 +114,7 @@ template: |
|
||||||
|
|
||||||
; Blacklist entries
|
; Blacklist entries
|
||||||
{{ range .blacklist -}}
|
{{ range .blacklist -}}
|
||||||
{{ to_punycode .Domain }} CNAME . ; {{ .Comment }}
|
{{ to_punycode .Domain }} CNAME . ; {{ .Comments }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
3
main.go
3
main.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -108,7 +107,7 @@ func main() {
|
||||||
func addIfNotExists(entries []entry, e entry) []entry {
|
func addIfNotExists(entries []entry, e entry) []entry {
|
||||||
for i, pe := range entries {
|
for i, pe := range entries {
|
||||||
if pe.Domain == e.Domain {
|
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
|
return entries
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type entry struct {
|
type entry struct {
|
||||||
Domain string
|
Domain string
|
||||||
Comment string
|
Comments []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type provider interface {
|
type provider interface {
|
||||||
|
|
|
@ -44,8 +44,8 @@ func (p providerdomainList) GetDomainList(d providerDefinition) ([]entry, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = append(entries, entry{
|
entries = append(entries, entry{
|
||||||
Domain: domain,
|
Domain: domain,
|
||||||
Comment: d.Name,
|
Comments: []string{d.Name},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,8 +63,8 @@ func (p providerHostFile) GetDomainList(d providerDefinition) ([]entry, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = append(entries, entry{
|
entries = append(entries, entry{
|
||||||
Domain: groups[1],
|
Domain: groups[1],
|
||||||
Comment: comment,
|
Comments: []string{comment},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue