mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
fix #14 Avoid too much api call times by creating a file to store last IP address
This commit is contained in:
parent
0b30f52e71
commit
508aa7321a
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,3 +32,4 @@ vendor/*
|
||||
/godns.iml
|
||||
/godns.ipr
|
||||
/godns.iws
|
||||
.current_ip
|
||||
|
@ -37,7 +37,6 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
|
||||
}()
|
||||
|
||||
for {
|
||||
|
||||
domainID := handler.GetDomain(domain.DomainName)
|
||||
|
||||
if domainID == -1 {
|
||||
@ -50,7 +49,18 @@ func (handler *DNSPodHandler) DomainLoop(domain *godns.Domain, panicChan chan<-
|
||||
log.Println("get_currentIP:", err)
|
||||
continue
|
||||
}
|
||||
log.Println("currentIp is:", currentIP)
|
||||
log.Println("currentIP is:", currentIP)
|
||||
|
||||
//Compare currentIP with saved IP
|
||||
savedIP := godns.LoadCurrentIP()
|
||||
log.Println("savedIP is:", savedIP)
|
||||
|
||||
if savedIP != "" && strings.TrimRight(currentIP, "\n") == strings.TrimRight(savedIP, "\n") {
|
||||
log.Printf("Current IP is not changed, no need to update...")
|
||||
continue
|
||||
} else {
|
||||
godns.SaveCurrentIP(currentIP)
|
||||
}
|
||||
|
||||
for _, subDomain := range domain.SubDomains {
|
||||
|
||||
|
@ -46,7 +46,17 @@ func (handler *HEHandler) DomainLoop(domain *godns.Domain, panicChan chan<- godn
|
||||
log.Println("get_currentIP:", err)
|
||||
continue
|
||||
}
|
||||
log.Println("currentIp is:", currentIP)
|
||||
log.Println("currentIP is:", currentIP)
|
||||
|
||||
//Compare currentIP with saved IP
|
||||
savedIP := godns.LoadCurrentIP()
|
||||
|
||||
if savedIP != "" && currentIP == savedIP {
|
||||
log.Printf("Current IP is not changed, no need to update...")
|
||||
continue
|
||||
} else {
|
||||
godns.SaveCurrentIP(currentIP)
|
||||
}
|
||||
|
||||
for _, subDomain := range domain.SubDomains {
|
||||
log.Printf("%s.%s Start to update record IP...\n", subDomain, domain.DomainName)
|
||||
|
16
utils.go
16
utils.go
@ -5,6 +5,8 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
)
|
||||
@ -67,3 +69,17 @@ func CheckSettings(config *Settings) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveCurrentIP(currentIP string) {
|
||||
ioutil.WriteFile("./.current_ip", []byte(currentIP), os.FileMode(0644))
|
||||
}
|
||||
|
||||
func LoadCurrentIP() string {
|
||||
content, err := ioutil.ReadFile("./.current_ip")
|
||||
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.Replace(string(content), "\n", "", -1)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user