Skip to content

not really an issue but just a suggestion for go modules  #3

@TotallyNotAHaxxer

Description

@TotallyNotAHaxxer

i like the idea of this module and I do think it can be useful to ALOT of things, however might I suggest making the example code a bit more- per say better and more professional?

for one we all know this is can be a useful module ( your giving me alot of nice ideas for an upcoming script ) however the example code is a bit- easy, this might be used in bigger lines of code so in the example you can make some extra functions and make it a bit easier for people to use in bigger sets , like so.

func checkErr(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
}

this will check if an error exists and so on im sure you have a 100% understanding of what this does

then you can add something maybe like a online checker to test if the device is online before scanning like so

func test() bool {
	_, err := http.Get("https://www.google.com")
	if err == nil {
		log.Fatal(err)
		return true
	} else {
		fmt.Println(Red("Device may have been disconnected from the network"))
		return false
	}
}

this will be a simple connection tester ( you could use dialup i just find this method easier )
so now the full example setting would be something like so

package main 



import (
  fmt

  scan "github.com/fberrez/go-scan"
)

func checkErr(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
}

func test() bool {
	_, err := http.Get("https://www.google.com")
	if err == nil {
		log.Fatal(err)
		return true
	} else {
		fmt.Println(Red("Device may have been disconnected from the network"))
		return false
	}
}

func main() {
  scan, err := scan.New("192.168.1.1/24")
  checkErr(err, err)
  
if err = scan.Scan(); err != nil {
    panic(err)
  }

  results, err := json.Marshal(scan.Result)
 checkErr(err, err) // use of function checking the error to chomp down the code a bit 

  fmt.Printf("%s", results)
**}**

just some help of advice to make it look alot more professional in the future ( this is not my best work but you get the idea )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions