Skip to content

Commit

Permalink
Revert "overide selected checks by flag or config file"
Browse files Browse the repository at this point in the history
This reverts commit 41c3c71.
  • Loading branch information
jreisinger committed Jun 7, 2024
1 parent 0ceb1b3 commit a08f623
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 73 deletions.
9 changes: 0 additions & 9 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ import (
"github.com/jreisinger/checkip"
)

// Use : function list to be used in checks
var Use = []checkip.Check{}

// AddUse : methode to add function in checks
func AddUse(s interface{}) {
Use = append(Use, s.(checkip.Check))
}

// All contains all available checks.
var All = []checkip.Check{
AbuseIPDB,
BlockList,
CinsScore,
Censys,
DBip,
DnsMX,
DnsName,
Expand Down
5 changes: 0 additions & 5 deletions check/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import (
"gopkg.in/yaml.v3"
)

// GetConfigValue export getConfigValue function for main
func GetConfigValue(key string) (string, error) {
return getConfigValue(key)
}

// getConfigValue tries to get value for key first from an environment variable
// then from a configuration file at $HOME/.checkip.yaml. If value is not found
// an empty string and nil is returned (i.e. it's not considered an error).
Expand Down
59 changes: 0 additions & 59 deletions cmd/checkip/checkip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import (
"log"
"net"
"os"
"reflect"
"runtime"
"strings"
"sync"

"github.com/jreisinger/checkip/check"
Expand All @@ -24,73 +21,17 @@ func init() {

var a = flag.Bool("a", false, "run all available checks")
var j = flag.Bool("j", false, "output all results in JSON")
var t = flag.String("t", "", "list of checks")
var c = flag.Int("c", 5, "IP addresses being checked concurrently")

type IpAndResults struct {
IP net.IP
Results cli.Results
}

var funcRegistry = make(map[string]interface{})
var funcDefaultRegistry = make(map[string]int)

func init() {
for _, v := range check.All {
name := runtime.FuncForPC(reflect.ValueOf(v).Pointer()).Name()
funcRegistry[name] = v
}
for _, v := range check.Default {
name := runtime.FuncForPC(reflect.ValueOf(v).Pointer()).Name()
funcDefaultRegistry[name] = 1
}
}

func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s [-flag] IP [IP liste]\n", os.Args[0])

flag.PrintDefaults()

fmt.Fprintf(os.Stderr, " * All checks : ")
for v := range funcRegistry {
v = strings.Replace(v, "github.com/jreisinger/checkip/check.", "", -1)
fmt.Fprintf(os.Stderr, "%s, ", v)
}
fmt.Fprintln(os.Stderr, "")
fmt.Fprintf(os.Stderr, " * Default checks : ")
for v := range funcDefaultRegistry {
v = strings.Replace(v, "github.com/jreisinger/checkip/check.", "", -1)
fmt.Fprintf(os.Stderr, "%s, ", v)
}
fmt.Fprintln(os.Stderr, "")
}

flag.Parse()

tcheck := ""
if *t == "" {
tcheck, _ = check.GetConfigValue("CHECKS")
} else {
tcheck = *t
}
tcheck = strings.Replace(tcheck, " ", "", -1)
split := strings.Split(tcheck, ",")
for _, s := range split {
fname := "github.com/jreisinger/checkip/check." + s
if funcRegistry[fname] != nil {
check.AddUse(funcRegistry[fname])
}
}

use := check.Use

checks := check.Default
if len(use) > 0 {
fmt.Println("Checks: " + tcheck)
checks = use
}

if *a {
checks = check.All
}
Expand Down

0 comments on commit a08f623

Please sign in to comment.