From a08f623f187d6d7069b38e64946bf05c6615c20e Mon Sep 17 00:00:00 2001 From: Jozef Reisinger Date: Fri, 7 Jun 2024 16:30:09 +0200 Subject: [PATCH] Revert "overide selected checks by flag or config file" This reverts commit 41c3c714bde5546fcbba05c425a4e8b69f1c2c56. --- check/check.go | 9 ------- check/config.go | 5 ---- cmd/checkip/checkip.go | 59 ------------------------------------------ 3 files changed, 73 deletions(-) diff --git a/check/check.go b/check/check.go index a4f9e1b..ffe0915 100644 --- a/check/check.go +++ b/check/check.go @@ -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, diff --git a/check/config.go b/check/config.go index 719d141..23fdbb1 100644 --- a/check/config.go +++ b/check/config.go @@ -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). diff --git a/cmd/checkip/checkip.go b/cmd/checkip/checkip.go index 2a798e3..aa798bf 100644 --- a/cmd/checkip/checkip.go +++ b/cmd/checkip/checkip.go @@ -8,9 +8,6 @@ import ( "log" "net" "os" - "reflect" - "runtime" - "strings" "sync" "github.com/jreisinger/checkip/check" @@ -24,7 +21,6 @@ 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 { @@ -32,65 +28,10 @@ type IpAndResults struct { 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 }