48 lines
706 B
Go
48 lines
706 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
var timeout = time.Duration(time.Second)
|
|
|
|
func main() {
|
|
if len(os.Args) == 1 {
|
|
fmt.Println("Please provide a URL")
|
|
return
|
|
}
|
|
|
|
if len(os.Args) == 3 {
|
|
temp, err := strconv.Atoi(os.Args[2])
|
|
if err != nil {
|
|
fmt.Println("Using Default Timeout!")
|
|
} else {
|
|
timeout = time.Duration(time.Duration(temp) * time.Second)
|
|
}
|
|
}
|
|
|
|
URL := os.Args[1]
|
|
|
|
client := http.Client{
|
|
Timeout: timeout,
|
|
}
|
|
client.Get(URL)
|
|
|
|
data, err := client.Get(URL)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
} else {
|
|
defer data.Body.Close()
|
|
_, err := io.Copy(os.Stdout, data.Body)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
}
|
|
}
|