-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.go
More file actions
42 lines (40 loc) · 758 Bytes
/
Copy pathfetch.go
File metadata and controls
42 lines (40 loc) · 758 Bytes
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
package main
import (
"bufio"
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
var url string
files := os.Args[1:]
for _, arg := range files {
f, err := os.Open(arg)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
continue
}
defer f.Close()
input := bufio.NewScanner(f)
for input.Scan() {
url = input.Text()
if strings.HasPrefix(url, "https://") != true {
url = fmt.Sprintf("https://%v", url)
}
resp, err := http.Get(url)
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: %v\n", err)
continue
}
b, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
fmt.Fprintf(os.Stderr, "fetch: %v\n", err)
continue
}
fmt.Printf("%s : [%s]\n", url, b)
}
}
}