mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 07:40:48 -08:00
31 lines
604 B
Go
31 lines
604 B
Go
package http
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type ClientOption func(client *http.Client)
|
|
|
|
func WithTimeout(timeout time.Duration) ClientOption {
|
|
return func(client *http.Client) {
|
|
client.Timeout = timeout
|
|
}
|
|
}
|
|
|
|
func Client(opts ...ClientOption) *http.Client {
|
|
return ClientWithContext(context.Background(), opts...)
|
|
}
|
|
|
|
// ClientWithContext returns an HTTP client with the specified context and options.
|
|
func ClientWithContext(ctx context.Context, opts ...ClientOption) *http.Client {
|
|
c := &http.Client{
|
|
Transport: Transport(ctx),
|
|
}
|
|
for _, opt := range opts {
|
|
opt(c)
|
|
}
|
|
return c
|
|
}
|