Skip to content

Commit

Permalink
add Makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Shuaipeng Yu <[email protected]>
  • Loading branch information
jackysp committed Jan 28, 2020
1 parent d743f17 commit b49578a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
23 changes: 16 additions & 7 deletions und.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit b49578a

Please sign in to comment.