Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ import (
"io"
"math/rand"
"os"
"os/user"
"time"
)

func prepareBenchmarkNameservers(nsStore nsInfoMap) {
if appConfiguration.nameserver == "" {
// read global nameservers from given file
fmt.Println("trying to load nameservers from datasrc/nameserver-globals.csv")
readNameserversFromFile(nsStore, "datasrc/nameserver-globals.csv") // TODO: Split read and Load
// @ TODO refactor - there shouldn't be the same code in if and else
// (but atm this is the only safe way)...
if _, err := os.Stat("datasrc/nameserver-globals.csv"); err == nil {
fmt.Println("trying to load nameservers from datasrc/nameserver-globals.csv")
readNameserversFromFile(nsStore, "datasrc/nameserver-globals.csv") // TODO: Split read and Load
} else if usr, err := user.Current(); err == nil{
fmt.Println("trying to load nameservers from ~/.config/nameinator/nameserver-globals.csv")
readNameserversFromFile(nsStore, usr.HomeDir + "/.config/nameinator/nameserver-globals.csv") // TODO: Split read and Load
} else {
fmt.Println("trying to load nameservers from datasrc/nameserver-globals.csv")
readNameserversFromFile(nsStore, "datasrc/nameserver-globals.csv") // TODO: Split read and Load
}
} else {
loadNameserver(nsStore, appConfiguration.nameserver, "givenByParameter")
}
Expand All @@ -23,8 +34,21 @@ func prepareBenchmarkNameservers(nsStore nsInfoMap) {
func prepareBenchmarkDomains(dStore dInfoMap) {
var domains []string
// read domains from given file
fmt.Println("trying to load domains from datasrc/alexa-top-2000-domains.txt")
alldomains, err := readloadDomainsFromFile("datasrc/alexa-top-2000-domains.txt")
var err error
var alldomains []string
var usr *user.User
// @ TODO refactor - there shouldn't be the same code in if and else
// (but atm this is the only safe way)...
if _, err = os.Stat("datasrc/alexa-top-2000-domains.txt"); err == nil {
fmt.Println("trying to load domains from datasrc/alexa-top-2000-domains.txt")
alldomains, err = readloadDomainsFromFile("datasrc/alexa-top-2000-domains.txt")
} else if usr, err = user.Current(); err == nil{
fmt.Println("trying to load domains from ~/.config/nameinator/domains.txt")
alldomains, err = readloadDomainsFromFile(usr.HomeDir + "/.config/nameinator/domains.txt")
} else {
fmt.Println("trying to load domains from datasrc/alexa-top-2000-domains.txt")
alldomains, err = readloadDomainsFromFile("datasrc/alexa-top-2000-domains.txt")
}
_ = err // TODO: Exception handling in case that the files do not exist
// randomize domains from file to avoid cached results
rand.Seed(time.Now().UnixNano())
Expand Down