Created
March 15, 2018 12:29
-
-
Save greut/c23368b3f4f662b73ca879a5f58643e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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