-
Notifications
You must be signed in to change notification settings - Fork 3
/
output.go
53 lines (48 loc) · 1.13 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"io"
"os"
"time"
)
func writeOutput(results []WebURL, outputFile string, showDates bool) error {
var writer io.Writer = os.Stdout
if outputFile != "" {
file, err := os.Create(outputFile)
if err != nil {
return fmt.Errorf("error opening output file: %v", err)
}
defer file.Close()
writer = file
}
for _, w := range results {
if showDates {
d, err := time.Parse("20060102150405", w.Date)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse date [%s] for URL [%s]\n", w.Date, w.URL)
continue
}
if _, err := fmt.Fprintf(writer, "%s %s\n", d.Format(time.RFC3339), w.URL); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
} else {
if _, err := fmt.Fprintln(writer, w.URL); err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
}
}
return nil
}
func getVersionURLs(domains []string) error {
for _, u := range domains {
versions, err := getVersions(u)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting versions for %s: %v\n", u, err)
continue
}
for _, v := range versions {
fmt.Println(v)
}
}
return nil
}