Skip to content

Commit

Permalink
add concurrency on --all and --export
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo <[email protected]>
  • Loading branch information
lfaoro committed Jun 5, 2019
1 parent c13a707 commit 6f90253
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 15 additions & 7 deletions cmd/flares/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"
"path"
"sync"

"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -96,21 +97,28 @@ func main() {
zones, err := dns.Zones()
fatalIfErr(err)

wg := sync.WaitGroup{}
for id, domain := range zones {
if debugFlag {
fmt.Println(id, domain)
}

table, err := dns.TableFor(domain)
fatalIfErr(err)
wg.Add(1)
go func() {
table, err := dns.TableFor(domain)
fatalIfErr(err)

if c.Bool("export") {
export(domain, table)
continue
}
if c.Bool("export") {
export(domain, table)
} else {
fmt.Println(string(table))
}

wg.Done()
}()

fmt.Println(string(table))
}
wg.Wait()

return nil
}
Expand Down
4 changes: 1 addition & 3 deletions internal/cloudflare/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package cloudflare

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -57,8 +56,8 @@ func (cf Cloudflare) TableFor(domain string) ([]byte, error) {
// ref: https://api.cloudflare.com/#zone-list-zones
func (cf Cloudflare) Zones() (map[string]string, error) {
var result = map[string]string{}
var count = 1

var count = 1
for {
endpoint := cf.API + "/zones"
u, err := url.Parse(endpoint)
Expand Down Expand Up @@ -165,7 +164,6 @@ func (cf Cloudflare) zoneIDFor(domain string) (string, error) {
return "", err
}
if !response.Success {
fmt.Println("DEBUG:", response.Errors)
return "", errors.New(response.Errors[0].Message)
}
if len(response.Result) == 0 {
Expand Down

0 comments on commit 6f90253

Please sign in to comment.