Skip to content

Commit

Permalink
golint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gombadi committed Sep 28, 2015
1 parent f6a5521 commit 222ce63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/miekg/dns"
)

// ndCounts holds various statistics about the running system
// NodeCounts holds various statistics about the running system for use in html templates
type NodeCounts struct {
NdStatus []uint32 // number of nodes at each of the 4 statuses - RG, CG, WG, NG
NdStarts []uint32 // number of crawles started last startcrawlers run
Expand Down
17 changes: 9 additions & 8 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type JNetwork struct {
Name string
Desc string
Id string
ID string
Port uint16
Pver uint32
DNSName string
Expand All @@ -30,7 +30,7 @@ func createNetFile() {

// create a struct to encode with json
jnw := &JNetwork{
Id: "0xabcdef01",
ID: "0xabcdef01",
Port: 1234,
Pver: 70001,
TTL: 600,
Expand Down Expand Up @@ -62,7 +62,7 @@ func createNetFile() {
func loadNetwork(fName string) (*dnsseeder, error) {
nwFile, err := os.Open(fName)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error reading network file: %v", err))
return nil, fmt.Errorf("Error reading network file: %v", err)
}

defer nwFile.Close()
Expand All @@ -71,7 +71,7 @@ func loadNetwork(fName string) (*dnsseeder, error) {

jsonParser := json.NewDecoder(nwFile)
if err = jsonParser.Decode(&jnw); err != nil {
return nil, errors.New(fmt.Sprintf("Error decoding network file: %v", err))
return nil, fmt.Errorf("Error decoding network file: %v", err)
}

return initNetwork(jnw)
Expand All @@ -80,11 +80,12 @@ func loadNetwork(fName string) (*dnsseeder, error) {
func initNetwork(jnw JNetwork) (*dnsseeder, error) {

if jnw.Port == 0 {
return nil, errors.New(fmt.Sprintf("Invalid port supplied: %v", jnw.Port))
return nil, fmt.Errorf("Invalid port supplied: %v", jnw.Port)

}

if jnw.DNSName == "" {
return nil, errors.New(fmt.Sprintf("No DNS Hostname supplied"))
return nil, fmt.Errorf("No DNS Hostname supplied")
}

// init the seeder
Expand All @@ -98,9 +99,9 @@ func initNetwork(jnw JNetwork) (*dnsseeder, error) {
seeder.dnsHost = jnw.DNSName

// conver the network magic number to a Uint32
t1, err := strconv.ParseUint(jnw.Id, 0, 32)
t1, err := strconv.ParseUint(jnw.ID, 0, 32)
if err != nil {
return nil, errors.New(fmt.Sprintf("Error converting Network Magic number: %v", err))
return nil, fmt.Errorf("Error converting Network Magic number: %v", err)
}
seeder.id = wire.BitcoinNet(t1)

Expand Down
6 changes: 3 additions & 3 deletions seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ func isDuplicateSeeder(s *dnsseeder) (bool, error) {
// check for duplicate seeders with the same details
for _, v := range config.seeders {
if v.id == s.id {
return true, errors.New(fmt.Sprintf("Duplicate Magic id. Already loaded for %s so can not be used for %s", v.id, v.name, s.name))
return true, fmt.Errorf("Duplicate Magic id. Already loaded for %s so can not be used for %s", v.id, v.name, s.name)
}
if v.dnsHost == s.dnsHost {
return true, errors.New(fmt.Sprintf("Duplicate DNS names. Already loaded %s for %s so can not be used for %s", v.dnsHost, v.name, s.name))
return true, fmt.Errorf("Duplicate DNS names. Already loaded %s for %s so can not be used for %s", v.dnsHost, v.name, s.name)
}
}
return false, nil
}

/*
*/
*/
20 changes: 10 additions & 10 deletions seeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestGetNonStdIP(t *testing.T) {

var ip_tests = []struct {
var iptests = []struct {
rip string
port uint16
encip string
Expand All @@ -20,10 +20,10 @@ func TestGetNonStdIP(t *testing.T) {
{"123.213.132.231", 34, "12.91.0.34"},
}

for _, x := range ip_tests {
newip := getNonStdIP(net.ParseIP(x.rip), x.port)
if newip.String() != x.encip {
t.Errorf("real-ip: %s real-port: %v encoded-ip: %v expected-ip: %s", x.rip, x.port, newip, x.encip)
for _, atest := range iptests {
newip := getNonStdIP(net.ParseIP(atest.rip), atest.port)
if newip.String() != atest.encip {
t.Errorf("real-ip: %s real-port: %v encoded-ip: %v expected-ip: %s", atest.rip, atest.port, newip, atest.encip)
}
}
}
Expand All @@ -46,11 +46,11 @@ func TestAddnNa(t *testing.T) {
}
s.theList = make(map[string]*node)

for _, x := range td {
for _, atest := range td {
// Test NewNetAddress.
tcpAddr := &net.TCPAddr{
IP: net.ParseIP(x.ip),
Port: x.port,
IP: net.ParseIP(atest.ip),
Port: atest.port,
}
na, _ := wire.NewNetAddress(tcpAddr, 0)
ndName := net.JoinHostPort(na.IP.String(), strconv.Itoa(int(na.Port)))
Expand All @@ -59,8 +59,8 @@ func TestAddnNa(t *testing.T) {
if result != true {
t.Errorf("failed to create new node: %s", ndName)
}
if s.theList[ndName].dnsType != x.dnsType {
t.Errorf("node: %s dnsType:%v expected: %v", ndName, s.theList[ndName].dnsType, x.dnsType)
if s.theList[ndName].dnsType != atest.dnsType {
t.Errorf("node: %s dnsType:%v expected: %v", ndName, s.theList[ndName].dnsType, atest.dnsType)
}
}

Expand Down

0 comments on commit 222ce63

Please sign in to comment.