Added command line flag for domain

This commit is contained in:
Philipp Böhm 2014-07-15 21:48:15 +02:00
parent 0b1e3055d5
commit b3d993b0eb
1 changed files with 26 additions and 27 deletions

27
ddns.go
View File

@ -2,6 +2,7 @@ package main
import (
"bufio"
"flag"
"fmt"
"github.com/gin-gonic/gin"
"github.com/pboehm/ddns/connection"
@ -58,7 +59,6 @@ func RunBackend() {
fmt.Printf("END\n")
}
}
func RunWebService() {
@ -153,29 +153,28 @@ func GetRemoteAddr(req *http.Request) (string, error) {
}
}
func ExtractConfigVariables() {
// get the domain in the right format
DdnsDomain = os.Getenv("DDNS_DOMAIN")
func ValidateCommandArgs() {
if DdnsDomain == "" {
log.Fatal(
"You have to set your Subdomain through the DDNS_DOMAIN env variable")
}
if ! strings.HasPrefix(DdnsDomain, ".") {
log.Fatal("You have to supply the domain via --domain=DOMAIN")
} else if !strings.HasPrefix(DdnsDomain, ".") {
// get the domain in the right format
DdnsDomain = "." + DdnsDomain
}
}
func init() {
flag.StringVar(&DdnsDomain, "domain", "",
"The subdomain which should be handled by DDNS")
}
func main() {
flag.Parse()
ValidateCommandArgs()
if len(os.Args) < 2 {
if len(flag.Args()) != 1 {
usage()
}
ExtractConfigVariables()
cmd := os.Args[1]
cmd := flag.Args()[0]
switch cmd {
case "backend":