Skip to content

Commit 0025da3

Browse files
committed
Code Beautify
1 parent bc46839 commit 0025da3

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

cmd/cloudflare-ddns/main.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
package main
22

33
import (
4-
"github.com/claudio4/cloudflare-ddns/pkg/cloudflare"
54
"flag"
6-
"os"
75
"fmt"
6+
"github.com/claudio4/cloudflare-ddns/pkg/cloudflare"
87
"github.com/claudio4/cloudflare-ddns/pkg/ip"
8+
"os"
99
)
1010

1111
func main() {
12-
var email, apikey, zoneID, domain string
13-
flag.StringVar(&email, "email", "", "Your Cloudflare email")
14-
flag.StringVar(&apikey, "key", "", "Your Cloudflare API Key")
15-
flag.StringVar(&zoneID, "zoneid", "", "Domain's zone ID")
16-
flag.StringVar(&domain, "domain", "", "Domain to change")
17-
flag.Parse()
18-
if email == "" || apikey == "" || zoneID == "" || domain == "" {
19-
fmt.Println("Missing parameters: All the following parameters are required")
20-
flag.PrintDefaults()
21-
os.Exit(1)
22-
}
12+
var email, apikey, zoneID, domain string
13+
flag.StringVar(&email, "email", "", "Your Cloudflare email")
14+
flag.StringVar(&apikey, "key", "", "Your Cloudflare API Key")
15+
flag.StringVar(&zoneID, "zoneid", "", "Domain's zone ID")
16+
flag.StringVar(&domain, "domain", "", "Domain to change")
17+
flag.Parse()
18+
if email == "" || apikey == "" || zoneID == "" || domain == "" {
19+
fmt.Println("Missing parameters: All the following parameters are required")
20+
flag.PrintDefaults()
21+
os.Exit(1)
22+
}
2323

24-
IP, err := ip.Get()
25-
if err != nil {
26-
fmt.Fprintln(os.Stderr, err.Error())
27-
os.Exit(10)
28-
}
24+
IP, err := ip.Get()
25+
if err != nil {
26+
fmt.Fprintln(os.Stderr, err.Error())
27+
os.Exit(10)
28+
}
2929

30-
id, content, ttl, err := cloudflare.GetRecordDetails(email, apikey, zoneID, domain)
31-
if err != nil {
32-
fmt.Fprintln(os.Stderr, err.Error())
33-
os.Exit(20)
34-
}
30+
id, content, ttl, err := cloudflare.GetRecordDetails(email, apikey, zoneID, domain)
31+
if err != nil {
32+
fmt.Fprintln(os.Stderr, err.Error())
33+
os.Exit(20)
34+
}
3535

36-
if content == IP {
37-
os.Exit(0)
38-
}
36+
if content == IP {
37+
os.Exit(0)
38+
}
3939

40-
err = cloudflare.SetRecord(email, apikey, zoneID, id, "A", domain, IP, ttl)
41-
if err != nil {
42-
fmt.Fprintln(os.Stderr, err.Error())
43-
os.Exit(30)
44-
}
40+
err = cloudflare.SetRecord(email, apikey, zoneID, id, "A", domain, IP, ttl)
41+
if err != nil {
42+
fmt.Fprintln(os.Stderr, err.Error())
43+
os.Exit(30)
44+
}
4545
}

pkg/ip/ip.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package ip
22

33
import (
4-
"strings"
54
"github.com/pkg/errors"
65
"io/ioutil"
76
"net/http"
7+
"strings"
88
)
99

1010
//Get Returns your ip
1111
func Get() (string, error) {
12-
res, err := http.Get("https://checkip.amazonaws.com/")
13-
if err != nil {
14-
return "", errors.Wrap(err, "Error requesting the ip")
15-
}
16-
defer res.Body.Close()
12+
res, err := http.Get("https://checkip.amazonaws.com/")
13+
if err != nil {
14+
return "", errors.Wrap(err, "Error requesting the ip")
15+
}
16+
defer res.Body.Close()
1717

18-
ip, err := ioutil.ReadAll(res.Body)
19-
if err != nil {
20-
return "", errors.Wrap(err, "Error reading the request")
21-
}
18+
ip, err := ioutil.ReadAll(res.Body)
19+
if err != nil {
20+
return "", errors.Wrap(err, "Error reading the request")
21+
}
2222

23-
return strings.TrimSpace(string(ip)), nil
23+
return strings.TrimSpace(string(ip)), nil
2424
}

0 commit comments

Comments
 (0)