set timeout for clients

This commit is contained in:
Selin Kurt 2019-10-21 20:55:37 +03:00
parent 43825687bb
commit c2fdbaf6ce

View File

@ -0,0 +1,34 @@
// In this example, we set timeout for clients
package main
import (
"fmt"
"net/http"
"time"
)
func sendClient(url string) {
client := http.Client{
Timeout: time.Duration(10 * time.Second),
}
resp, err := client.Get(url)
if err != nil {
fmt.Println("ERROR: Failed to Client \"" + url + "\"")
return
}
// fmt.Println(resp)
defer resp.Body.Close()
}
func main() {
url := "https://gobyexample.com/"
sendClient(url)
}