mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
mutil domain support & split with comma
Signed-off-by: jerrylou <gunsluo@gmail.com>
This commit is contained in:
parent
63f39bad94
commit
25bd050669
@ -69,8 +69,7 @@ docker pull timothyye/godns:1.0
|
|||||||
docker run -d --name godns --restart=always \
|
docker run -d --name godns --restart=always \
|
||||||
-e EMAIL=your_dnspod_account \
|
-e EMAIL=your_dnspod_account \
|
||||||
-e PASSWORD=your_dnspod_password \
|
-e PASSWORD=your_dnspod_password \
|
||||||
-e DOMAIN=your_domain \
|
-e DOMAINS="your_domain1,your_domain2" DOCKER_IMAGE_ID
|
||||||
-e SUB_DOMAIN=your_sub_domain DOCKER_IMAGE_ID
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
33
settings.go
33
settings.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Domain struct {
|
type Domain struct {
|
||||||
@ -41,13 +42,33 @@ func LoadSettings(configPath string, settings *Settings) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//LoadDomains -- Load domains from domains json
|
//LoadDomains -- Load domains from domains string
|
||||||
func LoadDomains(domainsJson string, domains *[]Domain) error {
|
func LoadDomains(domainsOrginStr string, domains *[]Domain) error {
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(domainsJson), domains)
|
domainsMap := make(map[string]*Domain)
|
||||||
if err != nil {
|
domainsArray := strings.Split(domainsOrginStr, ",")
|
||||||
fmt.Println("Error occurs while unmarshal domains json, please make sure domains json config correct!")
|
for _, host := range domainsArray {
|
||||||
return err
|
dotCount := strings.Count(host, ".")
|
||||||
|
if dotCount < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
len := len(host)
|
||||||
|
pos := strings.Index(host, ".")
|
||||||
|
subDomain := host[0:pos]
|
||||||
|
domainName := host[pos+1 : len]
|
||||||
|
|
||||||
|
if d, exist := domainsMap[domainName]; exist {
|
||||||
|
d.SubDomains = append(d.SubDomains, subDomain)
|
||||||
|
} else {
|
||||||
|
d := new(Domain)
|
||||||
|
d.DomainName = domainName
|
||||||
|
d.SubDomains = append(d.SubDomains, subDomain)
|
||||||
|
domainsMap[domainName] = d
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range domainsMap {
|
||||||
|
*domains = append(*domains, *d)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user