Skip to content
Snippets Groups Projects
Commit 4631be1b authored by Erick Hitter's avatar Erick Hitter
Browse files

Proper logging

parent 6bde3ce6
No related branches found
No related tags found
No related merge requests found
......@@ -4,20 +4,30 @@ import (
"fmt"
"github.com/joshbetz/config"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
)
var (
cfg *config.Config
ipv4Endpoint string
ipv6Endpoint string
logger *log.Logger
)
// Parse config
func init() {
cfg = config.New("config.json")
// Logging
logOpts := log.Ldate | log.Ltime | log.LUTC | log.Lshortfile
logger = log.New(os.Stdout, "", logOpts)
logger.Println("PINGING dyndnsd ENDPOINT")
// Configuration
cfg = config.New("config.json")
cfg.Get("ipv4_endpoint", &ipv4Endpoint)
cfg.Get("ipv6_endpoint", &ipv6Endpoint)
}
......@@ -27,6 +37,8 @@ func main() {
// Base URL
endpoint, err := buildEndpointUrl()
if err != nil {
logger.Println("Couldn't build endpoint URL")
logger.Printf("%s", err)
return
}
......@@ -37,27 +49,32 @@ func main() {
query.Set("myip", ipv4)
endpoint.RawQuery = query.Encode()
} else {
logger.Println("Couldn't retrieve IPv4 address")
logger.Printf("%s", err)
return
}
fmt.Println(endpoint)
// IPv6 is optional
ipv6, err := getUrl(ipv6Endpoint)
if err == nil {
query := endpoint.Query()
query.Set("myip6", ipv6)
endpoint.RawQuery = query.Encode()
} else {
logger.Println("Couldn't retrieve IPv6 address")
logger.Printf("%s", err)
}
// Send the update
dyndns, err := getUrl(endpoint.String())
if err != nil {
logger.Println("Couldn't update dyndnsd endpoint")
logger.Printf("%s", err)
return
}
// TODO: better formatting
fmt.Println(dyndns)
logger.Println("SUCCESS! Ping sent.")
logger.Printf("%s", dyndns)
}
// Build endpoint URL from configuration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment