Skip to content

Instantly share code, notes, and snippets.

@greut
Created March 15, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greut/c23368b3f4f662b73ca879a5f58643e1 to your computer and use it in GitHub Desktop.
Save greut/c23368b3f4f662b73ca879a5f58643e1 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"net/http"
"time"
)
func test(a, b, c int) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(a)*time.Second)
defer cancel()
client := &http.Client{
Timeout: time.Duration(b) * time.Second,
}
request, _ := http.NewRequest("GET", fmt.Sprintf("https://httpbin.org/delay/%d", c), nil)
if _, err := client.Do(request.WithContext(ctx)); err != nil {
fmt.Printf("Error: %s\n", err.Error())
}
}
func main() {
test(2, 1, 3)
test(1, 2, 3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment