1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00
This commit is contained in:
Timothy 2014-05-16 11:08:43 +08:00
parent 72292a4412
commit 9453b06b1c
3 changed files with 29 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/bitly/go-simplejson"
log "github.com/cihub/seelog"
"io/ioutil"
"net/http"
"net/url"
@ -17,6 +18,7 @@ func get_currentIP(url string) (string, error) {
if err != nil {
fmt.Println("Cannot get IP...")
log.Error("Cannot get IP...")
return "", err
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
log "github.com/cihub/seelog"
"os"
"strings"
"time"
@ -11,8 +12,10 @@ var Configuration Settings
func main() {
fmt.Println("Starting...")
log.Info("Starting...")
Configuration = LoadSettings()
initLog()
loop := make(chan bool)
go dns_loop(loop)
@ -21,6 +24,7 @@ func main() {
if !ret {
fmt.Println("Dns loop exited...")
log.Error("Dns loop exited...")
close(loop)
os.Exit(1)
@ -33,19 +37,27 @@ func dns_loop(loop chan bool) {
domain_id := get_domain(Configuration.Domain)
if domain_id == -1 {
continue
}
currentIP, _ := get_currentIP(Configuration.IP_Url)
sub_domain_id, ip := get_subdomain(domain_id, Configuration.Sub_domain)
fmt.Printf("currentIp is:%s\n", currentIP)
log.Infof("currentIp is:%s\n", currentIP)
//Continue to check the IP of sub-domain
if len(ip) > 0 && !strings.Contains(currentIP, ip) {
fmt.Println("Start to update record IP...")
log.Info("Start to update record IP...")
update_ip(domain_id, sub_domain_id, Configuration.Sub_domain, currentIP)
} else {
fmt.Println("Current IP is same as domain IP, no need to update...")
log.Info("Current IP is same as domain IP, no need to update...")
}
//Interval is 5 minutes

15
logger.go Normal file
View File

@ -0,0 +1,15 @@
package main
import log "github.com/cihub/seelog"
func initLog() {
testConfig := `
<seelog>
<outputs>
<rollingfile type="size" filename="run.log" maxsize="100" maxrolls="5" />
</outputs>
</seelog>
`
logger, _ := log.LoggerFromConfigAsBytes([]byte(testConfig))
log.ReplaceLogger(logger)
}