hq-go-http
is a Go (Golang) package for robust and flexible HTTP communication. It provides advanced features such as configurable retry policies, automatic fallback between HTTP/1.x and HTTP/2, and fluent request building with connection management.
- HTTP/1.x and HTTP/2 Support: The client maintains both HTTP/1.x and HTTP/2 clients. If the HTTP/1.x client encounters a specific transport error, the package automatically falls back to HTTP/2.
- Connection Management: Automatically manages idle connections to prevent resource exhaustion, ensuring that connections are properly drained and closed when no longer needed.
- Configurable Retry Logic: Customize the maximum number of retries, set minimum/maximum wait times, and choose your backoff strategy (e.g., exponential backoff with jitter).
To install hq-go-http
, run:
go get -v -u github.com/hueristiq/hq-go-http
Make sure your Go environment is set up properly (Go 1.x or later is recommended).
Here's a simple example demonstrating how to use hq-go-http
:
package main
import (
"log"
hqgohttp "github.com/hueristiq/hq-go-http"
)
func main() {
client := hqgohttp.NewClient(&hqgohttp.ClientConfiguration{
RetryMax: 3, // Max number of retries
Timeout: 10 * time.Second, // Request timeout
RetryWaitMin: 1 * time.Second, // Minimum wait between retries
RetryWaitMax: 5 * time.Second, // Maximum wait between retries
})
response, err := client.Get("https://example.com")
if err != nil {
log.Fatalf("Request failed: %v", err)
}
defer response.Body.Close()
// Handle response here
}
Contributions are welcome and encouraged! Feel free to submit Pull Requests or report Issues. For more details, check out the contribution guidelines.
A big thank you to all the contributors for your ongoing support!
This package is licensed under the MIT license. You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - Full MIT license text.