Initial commit
This commit is contained in:
37
cmd/qddns-client/main.go
Normal file
37
cmd/qddns-client/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/thequux/pdns-auto-update/common"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var server = flag.String("server", "https://dyn.thequux.com", "The URL of the DDNS server")
|
||||
var domain = flag.String("domain", "", "The domain to update")
|
||||
var token = flag.String("token", "", "The authorization token")
|
||||
|
||||
func main() {
|
||||
req, err := http.NewRequest("POST", *server+"/update/"+*domain, strings.NewReader(""))
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to create request: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
req.Header["Authorization"] = []string{"bearer " + *token}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stdout, "Failed to send request: %v", err)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to read response")
|
||||
}
|
||||
rj := common.Response{}
|
||||
json.Unmarshal(body, &rj)
|
||||
fmt.Printf("%v\n", rj)
|
||||
}
|
||||
Reference in New Issue
Block a user