Skip to content

Commit

Permalink
Added new flags to only get all,good,badurl output
Browse files Browse the repository at this point in the history
  • Loading branch information
MSTEWARDSON committed Oct 6, 2020
1 parent 4f772d8 commit 34d6383
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 762 deletions.
Binary file modified LinkStatus.exe
Binary file not shown.
79 changes: 66 additions & 13 deletions LinkStatus.go
@@ -1,7 +1,7 @@
/*
Name: Matthew Stewardson
Date: 23-09-20
Version: 1.0.4
Date: 06-10-20
Version: 0.1.4
Desc: Forth iteration of my link checker project. Bug fixes
Optional Features: Colour and Timeout
*/
Expand All @@ -20,6 +20,9 @@ import (
flag "github.com/spf13/pflag"
)

//Global Var's
var typeLink int = 1

/*
Opens and reads the given file into a single string. This string is then
checked for url's via a regex pattern.
Expand Down Expand Up @@ -58,37 +61,87 @@ func checkStatus(url string, i int) {
Timeout: 7 * time.Second,
}
response, err := client.Get(url)
if err != nil {
r.Println(i, " -> [ERROR] ", "URL: ", url)
} else {
if response.StatusCode >= 200 && response.StatusCode <= 299 {
g.Println(i, " -> [GOOD] ", response.StatusCode, "URL: ", url)
} else if response.StatusCode == 400 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)
} else if response.StatusCode == 404 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)

switch typeLink {
case 1:
if err != nil {
r.Println(i, " -> [ERROR] ", "URL: ", url)
} else {
if response.StatusCode >= 200 && response.StatusCode <= 299 {
g.Println(i, " -> [GOOD] ", response.StatusCode, "URL: ", url)
} else if response.StatusCode == 400 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)
} else if response.StatusCode == 404 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)
} else {
c.Println(i, " -> [UNKNOWN] URL: ", url)
}
defer response.Body.Close()
}
case 2:
if err != nil {
//Nothing
} else {
if response.StatusCode >= 200 && response.StatusCode <= 299 {
g.Println(i, " -> [GOOD] ", response.StatusCode, "URL: ", url)
}
defer response.Body.Close()
}
case 3:
if err != nil {
r.Println(i, " -> [ERROR] ", "URL: ", url)
} else {
c.Println(i, " -> [UNKNOWN] URL: ", url)
if response.StatusCode == 400 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)
} else if response.StatusCode == 404 {
r.Println(i, " -> [BAD] ", response.StatusCode, "URL: ", url)
} else {
c.Println(i, " -> [UNKNOWN] URL: ", url)
}
defer response.Body.Close()
}
defer response.Body.Close()
}
}

//Setting up the optional version command
var version = flag.BoolP("version", "v", false, "prints out version info")

//All flag
var all = flag.BoolP("all", "a", false, "Prints out all types of responses")

//Good flag
var good = flag.BoolP("good", "g", false, "Prints out only good responses")

//Bad flag
var bad = flag.BoolP("bad", "b", false, "Prints out only bad responses")

func main() {
flag.Parse()
if *version == true {
fmt.Println("LinkStatus version 0.1.4")
return
}
if *all == true {
fmt.Println("Outputting all types of links")
typeLink = 1
}
if *good == true {
fmt.Println("Outputting only good types of links")
typeLink = 2
}
if *bad == true {
fmt.Println("Outputting only bad types of links")
typeLink = 3
}
if len(os.Args) == 1 {
fmt.Println(`
Name: LinkStatus
Usage: go run LinkStatus.go filenames
Example: go run LinkStatus.go urls.txt
Version: go run LinkStatus.go -v or --version to check version.
All: go run LinkStatus.go -a or --all to output all types of responses
Good: go run LinkStatus.go -g or --good to output only good types of responses
Bad: go run LinkStatus.go -b or --bad to output only bad types of responses
`)
os.Exit(-1)
}
Expand Down

0 comments on commit 34d6383

Please sign in to comment.