grafana/pkg/infra/httpclient/provider.go
Marcus Efraimsson 348e76fc8e
Datasource: Shared HTTP client provider for core backend data sources and any data source using the data source proxy (#33439)
Uses new httpclient package from grafana-plugin-sdk-go introduced 
via grafana/grafana-plugin-sdk-go#328. 
Replaces the GetHTTPClient, GetTransport, GetTLSConfig methods defined 
on DataSource model.
Longer-term the goal is to migrate core HTTP backend data sources to use the 
SDK contracts and using httpclient.Provider for creating HTTP clients and such.

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
2021-05-19 23:53:41 +02:00

33 lines
1.2 KiB
Go

package httpclient
import (
"crypto/tls"
"net/http"
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
)
// Provider provides abilities to create http.Client, http.RoundTripper and tls.Config.
type Provider interface {
// New creates a new http.Client given provided options.
New(opts ...httpclient.Options) (*http.Client, error)
// GetTransport creates a new http.RoundTripper given provided options.
GetTransport(opts ...httpclient.Options) (http.RoundTripper, error)
// GetTLSConfig creates a new tls.Config given provided options.
GetTLSConfig(opts ...httpclient.Options) (*tls.Config, error)
}
// NewProvider creates a new HTTP client provider.
// Optionally provide ProviderOptions options that will be used as default if
// not specified in Options argument to Provider.New, Provider.GetTransport and
// Provider.GetTLSConfig.
// If no middlewares are provided in opts the DefaultMiddlewares() will be used. If you
// provide middlewares you have to manually add the DefaultMiddlewares() for it to be
// enabled.
// Note: Middlewares will be executed in the same order as provided.
func NewProvider(opts ...httpclient.ProviderOptions) *httpclient.Provider {
return httpclient.NewProvider(opts...)
}