-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/topscoder/fourohme | ||
|
||
go 1.18 | ||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package fourohme | ||
|
||
type Header struct { | ||
Key string | ||
Value string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package fourohme | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func ReadUrlsFromInput(urlPtr, filePtr *string) []string { | ||
var urls []string | ||
|
||
urls = readUrlsFromStdin() | ||
|
||
if urls != nil { | ||
return urls | ||
} | ||
|
||
if *filePtr != "" { | ||
urls = readUrlsFromFile(*filePtr) | ||
} else if *urlPtr != "" { | ||
urls = strings.Split(*urlPtr, ",") | ||
} | ||
|
||
return urls | ||
} | ||
|
||
func readUrlsFromStdin() []string { | ||
stat, _ := os.Stdin.Stat() | ||
if (stat.Mode() & os.ModeCharDevice) == 0 { | ||
// Read from stdin | ||
urls := make([]string, 0) | ||
scanner := bufio.NewScanner(os.Stdin) | ||
for scanner.Scan() { | ||
urls = append(urls, scanner.Text()) | ||
} | ||
|
||
return urls | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func readUrlsFromFile(filepath string) []string { | ||
file, err := os.Open(filepath) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
defer file.Close() | ||
|
||
var urls []string | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
urls = append(urls, scanner.Text()) | ||
} | ||
|
||
return urls | ||
} |
Oops, something went wrong.