Skip to content

Commit

Permalink
minor changes in checkip.go, cmd/checkip.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Reisinger committed Aug 31, 2021
1 parent 727b30e commit 3d26c85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion checkip.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Checker interface {

// Run runs checkers concurrently and returns the number of checkers that
// consider the IP address suspicious.
func Run(checkers map[string]Checker, ipaddr net.IP) int {
func Run(checkers []Checker, ipaddr net.IP) int {
ch := make(chan bool)
for _, checker := range checkers {
go func(checker Checker) {
Expand Down
14 changes: 9 additions & 5 deletions cmd/checkip.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ func main() {
"maxmind.com GeoLite2": &checkip.Geo{},
}

if !*s {
if *s {
var checkerSlice []checkip.Checker
for _, v := range checkers {
checkerSlice = append(checkerSlice, v)
}
n := checkip.Run(checkerSlice, ipaddr)
perc := float64(n) / float64(len(checkers)) * 100.0
fmt.Printf("%02.0f%% (%d/%d)\n", perc, n, len(checkers))
} else {
for k, v := range infoCheckers {
checkers[k] = v
}
checkip.RunAndPrint(checkers, ipaddr, "%-25s %s")
} else {
n := checkip.Run(checkers, ipaddr)
perc := float64(n) / float64(len(checkers)) * 100.0
fmt.Printf("%02.0f%% (%d/%d)\n", perc, n, len(checkers))
}

}

0 comments on commit 3d26c85

Please sign in to comment.