Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new feature that allow glob pattern passing and Documentation #7

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ accessibility of each url.

- Support for parallelization for the tool to run efficiently

- Only headers are requested when the urls are being checked.
- Only headers are requested when the urls are being checked.
- Allows passing glob pattern as an argument
```go
./urlChecker -g [glob-pattern]
```
For example,
```go
./urlChecker -g *.txt
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.15

require (
github.com/fatih/color v1.9.0
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4
mvdan.cc/xurls v1.1.0
mvdan.cc/xurls/v2 v2.2.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVc
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 h1:NK3O7S5FRD/wj7ORQ5C3Mx1STpyEMuFe+/F0Lakd1Nk=
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4/go.mod h1:FqD3ES5hx6zpzDainDaHgkTIqrPaI9uX4CVWqYZoQjY=
github.com/rogpeppe/go-internal v1.5.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
Expand Down
33 changes: 33 additions & 0 deletions urlChecker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
Expand All @@ -9,6 +10,7 @@ import (
"sync"
"time"

"github.com/mb0/glob"
"mvdan.cc/xurls/v2"
)

Expand Down Expand Up @@ -81,6 +83,8 @@ func checkURL(urls []string) {
}

func main() {
globFlag := flag.Bool("g", false, "Glob pattern")
flag.Parse()
//deal with non-file path, giving usage message
if len(os.Args) == 1 {
fmt.Println("help/usage message: To run this program, please pass an argument to it,i.e.: go run urlChecker.go urls.txt")
Expand All @@ -92,6 +96,35 @@ func main() {
return
}

if *globFlag {
//Assign the glob pattern provided to a local variable
pattern := flag.Args()[0]
//Read all files in the current directory
files, _ := ioutil.ReadDir(".")
//Create a globber object
globber, _ := glob.New(glob.Default())
//Loop through all files
for _, file := range files {
//Check if the file name match the glob pattern provided
matched, _ := globber.Match(pattern, file.Name())
//If matched then run the url check on that file
if matched {
//open file and read it
content, err := ioutil.ReadFile(file.Name())
if err != nil {
log.Fatal(err)
}
textContent := string(content)

fmt.Println(">> ***** UrlChecker is working now...... ***** <<")
fmt.Println("--------------------------------------------------------------------------------------------------")
//call functions to check the availability of each url
checkURL(extractURL(textContent))
}
}
return
}

//use for loop to deal with multiple file paths
i := 1
for i+1 <= len(os.Args) {
Expand Down