-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (36 loc) · 784 Bytes
/
main.go
File metadata and controls
39 lines (36 loc) · 784 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
// Fetch print the content found at a URL
package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
for _, url := range os.Args[1:] {
if strings.HasPrefix(url, "http://") {
resp, err := http.Get(url)
if err != nil {
fmt.Fprint(os.Stderr, "fetch: %v\n", err)
os.Exit(1)
}
//fmt.Printf("%s", resp.Body)
io.Copy(os.Stdout, resp.Body)
//b, err := io.ReadAll(resp.Body)
resp.Body.Close()
if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
//log.Fatal(err)
//os.Exit(1)
fmt.Println("Http Status:", resp.Status)
//continue
} else {
fmt.Fprint(os.Stderr, "fetch: reading %s: %v\n", url, err)
os.Exit(1)
}
} else {
fmt.Print("Please add prefix 'http://'!!!")
}
//fmt.Printf("%d", c)
}
}