From 4d63b93edb208ecf49896d1adba286b3d9e3796b Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 10 Sep 2018 10:44:23 +0800 Subject: [PATCH] add nic check --- config.default.yml | 1 + main.go | 20 ++++++++++++++++++++ modules/setting.go | 1 + 3 files changed, 22 insertions(+) diff --git a/config.default.yml b/config.default.yml index 6531bbc..f1bd0d4 100644 --- a/config.default.yml +++ b/config.default.yml @@ -1,3 +1,4 @@ +interface: eth0 domains: - name: domain.name subdomain: diff --git a/main.go b/main.go index f3449ac..cf78907 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "fmt" "io/ioutil" "log" + "net" "net/http" "regexp" "time" @@ -42,6 +43,25 @@ func main() { newR53() config = setting.LoadConfig(confpath) 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() if ok, err := checkIP(ip); err != nil || !ok { println("ip check fail") diff --git a/modules/setting.go b/modules/setting.go index b86f9de..3ad138d 100644 --- a/modules/setting.go +++ b/modules/setting.go @@ -11,6 +11,7 @@ import ( ) type Config struct { + NIC string `yaml:"interface"` Domains []struct { Name string `yaml:"name"` Sub []string `yaml:"subdomain,flow"`