discordBots/cmd/domaincheckbot/config/domain.go
2023-03-10 00:26:08 +01:00

40 lines
700 B
Go

package config
import (
_ "embed"
"encoding/json"
"github.com/disgoorg/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
}