move config parsing into the shared package
This commit is contained in:
parent
b7c07b86a0
commit
ce032237a8
|
@ -41,5 +41,5 @@ func (b *Backend) Run() error {
|
|||
}
|
||||
})
|
||||
|
||||
return r.Run(b.config.BackendListen)
|
||||
return r.Run(b.config.ListenBackend)
|
||||
}
|
||||
|
|
39
ddns.go
39
ddns.go
|
@ -1,56 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/pboehm/ddns/backend"
|
||||
"github.com/pboehm/ddns/frontend"
|
||||
"github.com/pboehm/ddns/shared"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var serviceConfig *shared.Config = &shared.Config{}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&serviceConfig.Domain, "domain", "",
|
||||
"The subdomain which should be handled by DDNS")
|
||||
|
||||
flag.StringVar(&serviceConfig.SOAFqdn, "soa_fqdn", "",
|
||||
"The FQDN of the DNS server which is returned as a SOA record")
|
||||
|
||||
flag.StringVar(&serviceConfig.BackendListen, "listen-backend", ":8057",
|
||||
"Which socket should the backend web service use to bind itself")
|
||||
|
||||
flag.StringVar(&serviceConfig.FrontendListen, "listen-frontend", ":8080",
|
||||
"Which socket should the frontend web service use to bind itself")
|
||||
|
||||
flag.StringVar(&serviceConfig.RedisHost, "redis", ":6379",
|
||||
"The Redis socket that should be used")
|
||||
|
||||
flag.IntVar(&serviceConfig.HostExpirationDays, "expiration-days", 10,
|
||||
"The number of days after a host is released when it is not updated")
|
||||
|
||||
flag.BoolVar(&serviceConfig.Verbose, "verbose", false,
|
||||
"Be more verbose")
|
||||
}
|
||||
|
||||
func validateCommandArgs() {
|
||||
if serviceConfig.Domain == "" {
|
||||
log.Fatal("You have to supply the domain via --domain=DOMAIN")
|
||||
} else if !strings.HasPrefix(serviceConfig.Domain, ".") {
|
||||
// get the domain in the right format
|
||||
serviceConfig.Domain = "." + serviceConfig.Domain
|
||||
}
|
||||
|
||||
if serviceConfig.SOAFqdn == "" {
|
||||
log.Fatal("You have to supply the server FQDN via --soa_fqdn=FQDN")
|
||||
}
|
||||
serviceConfig.Initialize()
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
validateCommandArgs()
|
||||
serviceConfig.Validate()
|
||||
|
||||
redis := shared.NewRedisBackend(serviceConfig)
|
||||
defer redis.Close()
|
||||
|
|
|
@ -121,7 +121,7 @@ func (f *Frontend) Run() error {
|
|||
})
|
||||
})
|
||||
|
||||
return r.Run(f.config.FrontendListen)
|
||||
return r.Run(f.config.ListenFrontend)
|
||||
}
|
||||
|
||||
// Get the Remote Address of the client. At First we try to get the
|
||||
|
|
|
@ -1,11 +1,55 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Verbose bool
|
||||
Domain string
|
||||
SOAFqdn string
|
||||
HostExpirationDays int
|
||||
FrontendListen string
|
||||
BackendListen string
|
||||
ListenFrontend string
|
||||
ListenBackend string
|
||||
RedisHost string
|
||||
}
|
||||
|
||||
func (c *Config) Initialize() {
|
||||
flag.StringVar(&c.Domain, "domain", "",
|
||||
"The subdomain which should be handled by DDNS")
|
||||
|
||||
flag.StringVar(&c.SOAFqdn, "soa_fqdn", "",
|
||||
"The FQDN of the DNS server which is returned as a SOA record")
|
||||
|
||||
flag.StringVar(&c.ListenBackend, "listen-backend", ":8057",
|
||||
"Which socket should the backend web service use to bind itself")
|
||||
|
||||
flag.StringVar(&c.ListenFrontend, "listen-frontend", ":8080",
|
||||
"Which socket should the frontend web service use to bind itself")
|
||||
|
||||
flag.StringVar(&c.RedisHost, "redis", ":6379",
|
||||
"The Redis socket that should be used")
|
||||
|
||||
flag.IntVar(&c.HostExpirationDays, "expiration-days", 10,
|
||||
"The number of days after a host is released when it is not updated")
|
||||
|
||||
flag.BoolVar(&c.Verbose, "verbose", false,
|
||||
"Be more verbose")
|
||||
}
|
||||
|
||||
func (c *Config) Validate() {
|
||||
flag.Parse()
|
||||
|
||||
if c.Domain == "" {
|
||||
log.Fatal("You have to supply the domain via --domain=DOMAIN")
|
||||
} else if !strings.HasPrefix(c.Domain, ".") {
|
||||
// get the domain in the right format
|
||||
c.Domain = "." + c.Domain
|
||||
}
|
||||
|
||||
if c.SOAFqdn == "" {
|
||||
log.Fatal("You have to supply the server FQDN via --soa_fqdn=FQDN")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue