Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timeout on GetProxy #3

Open
Akenaide opened this issue Jul 17, 2023 · 1 comment · Fixed by #4
Open

Add a timeout on GetProxy #3

Akenaide opened this issue Jul 17, 2023 · 1 comment · Fixed by #4
Labels
enhancement New feature or request

Comments

@Akenaide
Copy link
Owner

No description provided.

@Akenaide Akenaide added the enhancement New feature or request label Jul 17, 2023
@Akenaide Akenaide linked a pull request Jul 17, 2023 that will close this issue
@Akenaide
Copy link
Owner Author

Akenaide commented Jul 17, 2023

func main() {
	// Create a context with a timeout
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()

	// Create an HTTP client with the context
	client := &http.Client{}

	// Create a GET request
	req, err := http.NewRequestWithContext(ctx, "GET", "https://example.com", nil)
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}

	// Perform the request
	response, err := client.Do(req)
	if err != nil {
		// Check if the error is due to a timeout
		if ctx.Err() == context.DeadlineExceeded {
			fmt.Println("Request timed out")
			return
		}

		// Handle other errors
		fmt.Println("Error performing request:", err)
		return
	}
	defer response.Body.Close()

ctx is not used.

@Akenaide Akenaide reopened this Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant