Skip to content

Commit

Permalink
feat: increase timeout when calling Gandi API
Browse files Browse the repository at this point in the history
  • Loading branch information
mlcdf committed Apr 27, 2021
1 parent d2b7b66 commit 808a9ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions internal/gandi/gandi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import (
)

type Client struct {
Token string
Token string
timeout time.Duration
}

// New creates a new Client with a default timeout
func New(token string) *Client {
return &Client{token, time.Second * 20}
}

// DomainRecord represents a DNS Record
Expand All @@ -35,7 +41,7 @@ func (c *Client) Get(domain string, record string) ([]*DomainRecord, error) {

req.Header.Set("Authorization", "ApiKey "+c.Token)

client := &http.Client{Timeout: time.Second * 10}
client := &http.Client{Timeout: c.timeout}
res, err := client.Do(req)

if err != nil {
Expand Down Expand Up @@ -83,7 +89,7 @@ func (c *Client) Post(domain string, name string, ip *net.IP, ttl int) error {
req.Header.Set("Authorization", "ApiKey "+c.Token)
req.Header.Set("Content-type", "application/json")

client := &http.Client{Timeout: time.Second * 10}
client := &http.Client{Timeout: c.timeout}
res, err := client.Do(req)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func main() {
ipf = ipfinder.Ipify
}

gandiClient := &gandi.Client{Token: mustEnv("GANDI_TOKEN")}
gandiClient := gandi.New(mustEnv("GANDI_TOKEN"))
dyn := dyndns.New(ipf, gandiClient, discordClient)

err := dyn.Run(domainFlag, recordFlag, ttlFlag)
Expand Down

0 comments on commit 808a9ba

Please sign in to comment.