Skip to content

Commit

Permalink
English typo error fixed in log comments
Browse files Browse the repository at this point in the history
Signed-off-by: zerjioang <[email protected]>
  • Loading branch information
zerjioang committed Oct 21, 2021
1 parent 87a85c2 commit 93656d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

// Start executes the IP update method
func Start() error {
defer measureTime(time.Now(), "cloudflare ddns updater")
defer measureTime(time.Now(), "cloudflare DDNS-updater")
log.Println("Updating device IP. Please wait...")
p := datatypes.NewPayload()
log.Println("Requesting IP check for: ", p.Zone+"."+p.DNSRecord)
log.Println("Requesting IP check for: ", p.FQDN())
log.Println("Reading current device IP. Please wait...")
currIp := externalIP()
log.Println("Readed IP: ", currIp)
log.Println("Read IP: ", currIp)
log.Println("Connecting with Cloudflare services...")
return triggerDDNSUpdate(p.Token, p.Zone, "console", currIp)
return triggerDDNSUpdate(p, currIp)
}

// Monitor start a foreground monitor that updates every
Expand Down
9 changes: 5 additions & 4 deletions api/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"github.com/zerjioang/ddns-cloudflare/datatypes"
"log"

"github.com/cloudflare/cloudflare-go"
Expand All @@ -14,21 +15,21 @@ var (
)

// triggerDDNSUpdate returns CLoudFLare zone identifier for given zone name
func triggerDDNSUpdate(token string, zone string, aName string, currIp string) error {
func triggerDDNSUpdate(p *datatypes.Payload, currIp string) error {
// Construct a new API object
api, err := cloudflare.NewWithAPIToken(token)
api, err := cloudflare.NewWithAPIToken(p.Token)
if err != nil {
return err
}
// Fetch the zone ID
// Assuming example.com exists in your Cloudflare account already
zoneId, err := api.ZoneIDByName(zone)
zoneId, err := api.ZoneIDByName(p.Zone)
if err != nil {
return err
}
log.Println("Cloudflare ZONE ID: ", zoneId)
rr, err := api.DNSRecords(ctx, zoneId, cloudflare.DNSRecord{
Name: aName + "." + zone,
Name: p.FQDN(),
Type: "A",
})
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions datatypes/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type Payload struct {
Token string
}

// FQDN returns the FQDN
func (p Payload) FQDN() string {
return p.DNSRecord + "." + p.Zone
}

// NewPayload creates a new payload based on user requested data from ENV vars
func NewPayload() *Payload {
return &Payload{
Expand Down

0 comments on commit 93656d3

Please sign in to comment.