Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen428 committed May 18, 2022
1 parent 9a76bbb commit 8e68c5b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/unsavory/unsavory.go
Expand Up @@ -19,26 +19,25 @@ const (
// Client bundles all values necessary for API requests.
type Client struct {
client *http.Client

DryRun bool
Token string
dryRun bool
token string
}

// NewClient returns a configured unsavory.Client.
func NewClient(token string, dryRun bool) *Client {
client := &http.Client{
Timeout: time.Second * 5,
Timeout: time.Second * 15,
}

return &Client{
Token: token,
DryRun: dryRun,
token: token,
dryRun: dryRun,
client: client}
}

// Run fetches all URLs and kicks off the check process.
func (c *Client) Run() {
if c.DryRun {
if c.dryRun {
log.Printf("You are using dry run mode. No links will be deleted!\n\n")
}

Expand Down Expand Up @@ -98,7 +97,7 @@ func (c *Client) checkURL(u string) {
resp, err := c.client.Head(u)
if err != nil {
if _, ok := err.(*url.Error); ok {
log.Printf("Deleting (no such host): %s\n", u)
log.Printf("Deleting (%v): %s\n", u, err)
c.deleteURL(u)
}
} else {
Expand All @@ -113,7 +112,7 @@ func (c *Client) checkURL(u string) {
}

func (c *Client) deleteURL(url string) {
if !c.DryRun {
if !c.dryRun {
c.request("/posts/delete", url)
}
}
Expand All @@ -125,7 +124,7 @@ func (c *Client) request(path string, query ...string) *http.Response {
// Query params
params := url.Values{}
params.Add("format", "json")
params.Add("auth_token", c.Token)
params.Add("auth_token", c.token)
if len(query) > 0 {
params.Add("url", query[0])
}
Expand Down

0 comments on commit 8e68c5b

Please sign in to comment.