diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cd9a4f3 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +NAME=und +BINDIR=bin +LDFLAGS=-s -w -X "main.version=$(shell git describe --tags --dirty --always)" +GOBUILD=CGO_ENABLED=0 go build --ldflags="$(LDFLAGS)" -trimpath + +all: linux-arm64 linux-amd64 darwin-amd64 windows-amd64 + +linux-arm64: + GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + +linux-amd64: + GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + +darwin-amd64: + GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + +windows-amd64: + GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe \ No newline at end of file diff --git a/und.go b/und.go index 27e5222..134601e 100644 --- a/und.go +++ b/und.go @@ -2,31 +2,40 @@ package main import ( "flag" + "fmt" "log" + "os" "time" ) var ( - nmKey = flag.String("key", "12345", " To be replaced by your unique API key. Visit the API Manager page within your account for details.") - nmDomain = flag.String("domain", "namesilo.com", "The domain associated with the DNS resource record to modify") - nmHost = flag.String("host", "www", "The hostname to use (there is no need to include the \".DOMAIN\")") - nmInterval = flag.Duration("interval", 300*time.Second, "The seconds of updating interval") + fVersion = flag.Bool("v", false, "print version information and exit") + fKey = flag.String("k", "12345", " To be replaced by your unique API key. Visit the API Manager page within your account for details.") + fDomain = flag.String("d", "namesilo.com", "The domain associated with the DNS resource record to modify") + fHost = flag.String("h", "www", "The hostname to use (there is no need to include the \".DOMAIN\")") + fInterval = flag.Duration("i", 300*time.Second, "The seconds of updating interval") ) +var version = "None" + func main() { flag.Parse() + if *fVersion { + fmt.Println(version) + os.Exit(0) + } updateDNSLoop() } func updateDNSLoop() { - tick := time.NewTicker(*nmInterval) + tick := time.NewTicker(*fInterval) defer tick.Stop() for { select { case <-tick.C: - err := doUpdateDNS(*nmDomain, *nmHost, *nmKey) + err := doUpdateDNS(*fDomain, *fHost, *fKey) if err != nil { - log.Printf("[%v] update DNS record failed, domain:%s, host:%s, error:%v", time.Now().Format(time.RFC3339), *nmDomain, *nmHost, err) + log.Printf("[%v] update DNS record failed, domain:%s, host:%s, error:%v", time.Now().Format(time.RFC3339), *fDomain, *fHost, err) } } }