feat: -c argument to load the config from another path

This commit is contained in:
Fijxu 2025-01-26 00:23:51 -03:00
parent 7b82b1450c
commit 5f94658e1f
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -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() {