feat: -c argument to load the config from another path
This commit is contained in:
parent
7b82b1450c
commit
5f94658e1f
1 changed files with 13 additions and 2 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
|
@ -67,6 +68,11 @@ var resolver = &net.Resolver{
|
|||
d := net.Dialer{
|
||||
Timeout: time.Millisecond * time.Duration(5000),
|
||||
}
|
||||
if config.DnsServer == "" {
|
||||
// TODO: This is called two times. idk why
|
||||
log.Print("\"dnsServer\" key is empty. Using default DNS server")
|
||||
return d.DialContext(ctx, network, address)
|
||||
}
|
||||
return d.DialContext(ctx, network, config.DnsServer)
|
||||
},
|
||||
}
|
||||
|
@ -83,7 +89,7 @@ func (p *Porkbun) updateIp() {
|
|||
log.Print("Failed to retrieve IP address for domain " + p.Domain)
|
||||
}
|
||||
|
||||
log.Print("Current IP of the record " + p.Domain + "is " + dnsIp[0])
|
||||
log.Print("Current IP of the record " + p.Domain + " is " + dnsIp[0])
|
||||
|
||||
p.Data.Ip = getIpAddress()
|
||||
|
||||
|
@ -172,7 +178,12 @@ func doPostRequest(url string, data []byte) []byte {
|
|||
|
||||
func init() {
|
||||
client = &http.Client{}
|
||||
config = loadConfig("/etc/simple-ddns-client/config.json")
|
||||
var configPath string
|
||||
|
||||
flag.StringVar(&configPath, "c", "/etc/simple-ddns-client/config.json", "config.json path")
|
||||
flag.Parse()
|
||||
|
||||
config = loadConfig(configPath)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Add table
Reference in a new issue