remove lock, change run one time

This commit is contained in:
Jay 2018-09-26 19:42:38 +08:00
parent 4d63b93edb
commit e525ac65fe
3 changed files with 3 additions and 34 deletions

View File

@ -1,4 +1,3 @@
interface: eth0
domains: domains:
- name: domain.name - name: domain.name
subdomain: subdomain:

35
main.go
View File

@ -5,10 +5,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net"
"net/http" "net/http"
"regexp" "regexp"
"time"
"git.trj.tw/golang/go-aws-dns/modules" "git.trj.tw/golang/go-aws-dns/modules"
@ -44,31 +42,12 @@ func main() {
config = setting.LoadConfig(confpath) config = setting.LoadConfig(confpath)
fmt.Println(config) fmt.Println(config)
// wait nic
for {
nics, err := net.Interfaces()
if err != nil {
log.Fatal(err)
}
nicFlag := false
for _, v := range nics {
if v.Name == config.NIC {
nicFlag = true
}
}
if nicFlag == true {
break
}
time.Sleep(time.Second * 5)
}
ip = getMyIP() ip = getMyIP()
if ok, err := checkIP(ip); err != nil || !ok { if ok, err := checkIP(ip); err != nil || !ok {
println("ip check fail") println("ip check fail")
checkErr(err) checkErr(err)
} }
println(ip) println(ip)
mainLoc := make(chan bool)
var tmp []string var tmp []string
for _, it := range config.Domains { for _, it := range config.Domains {
@ -100,18 +79,10 @@ func main() {
fmt.Println(domains[0]) fmt.Println(domains[0])
go func() { for _, it := range domains {
for { it.updateRecord()
println("run loop") }
for _, it := range domains {
it.updateRecord()
}
time.Sleep(time.Minute * 5)
}
}()
<-mainLoc
} }
func newR53() { func newR53() {

View File

@ -11,7 +11,6 @@ import (
) )
type Config struct { type Config struct {
NIC string `yaml:"interface"`
Domains []struct { Domains []struct {
Name string `yaml:"name"` Name string `yaml:"name"`
Sub []string `yaml:"subdomain,flow"` Sub []string `yaml:"subdomain,flow"`