40 lines
680 B
Go
40 lines
680 B
Go
package config
|
|
|
|
import (
|
|
_ "embed"
|
|
"encoding/json"
|
|
"log"
|
|
"sort"
|
|
)
|
|
|
|
//go:embed domain.json
|
|
var domainsFiles []byte
|
|
|
|
var Domains []string
|
|
|
|
func init() {
|
|
err := json.Unmarshal(domainsFiles, &Domains)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func AddDomain(domain string) {
|
|
domains := append(Domains, domain)
|
|
sort.SliceStable(domains, func(i, j int) bool {
|
|
return domains[i] < domains[j]
|
|
})
|
|
Domains = removeDuplicate(domains)
|
|
}
|
|
|
|
func removeDuplicate[T string](sliceList []T) []T {
|
|
allKeys := make(map[T]bool)
|
|
var list []T
|
|
for _, item := range sliceList {
|
|
if _, value := allKeys[item]; !value {
|
|
allKeys[item] = true
|
|
list = append(list, item)
|
|
}
|
|
}
|
|
return list
|
|
}
|