| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package extensionmiddleware // import "go.opentelemetry.io/collector/extension/extensionmiddleware" |
| 5 |
|
| 6 |
import ( |
| 7 |
"net/http" |
| 8 |
|
| 9 |
"google.golang.org/grpc" |
| 10 |
) |
| 11 |
|
| 12 |
// HTTPClient is an interface for HTTP client middleware extensions. |
| 13 |
type HTTPClient interface { |
| 14 |
// GetHTTPRoundTripper wraps the provided client RoundTripper. |
| 15 |
GetHTTPRoundTripper(http.RoundTripper) (http.RoundTripper, error) |
| 16 |
} |
| 17 |
|
| 18 |
// GRPCClient is an interface for gRPC client middleware extensions. |
| 19 |
type GRPCClient interface { |
| 20 |
// GetGRPCClientOptions returns the gRPC dial options to use for client connections. |
| 21 |
GetGRPCClientOptions() ([]grpc.DialOption, error) |
| 22 |
} |
| 23 |
|
| 24 |
var _ HTTPClient = (*GetHTTPRoundTripperFunc)(nil) |
| 25 |
|
| 26 |
// GetHTTPRoundTripperFunc is a function that implements HTTPClient. |
| 27 |
type GetHTTPRoundTripperFunc func(base http.RoundTripper) (http.RoundTripper, error) |
| 28 |
|
| 29 |
func (f GetHTTPRoundTripperFunc) GetHTTPRoundTripper(base http.RoundTripper) (http.RoundTripper, error) { |
| 30 |
if f == nil { |
| 31 |
return base, nil |
| 32 |
} |
| 33 |
return f(base) |
| 34 |
} |
| 35 |
|
| 36 |
var _ GRPCClient = (*GetGRPCClientOptionsFunc)(nil) |
| 37 |
|
| 38 |
// GetGRPCClientOptionsFunc is a function that implements GRPCClient. |
| 39 |
type GetGRPCClientOptionsFunc func() ([]grpc.DialOption, error) |
| 40 |
|
| 41 |
func (f GetGRPCClientOptionsFunc) GetGRPCClientOptions() ([]grpc.DialOption, error) { |
| 42 |
if f == nil { |
| 43 |
return nil, nil |
| 44 |
} |
| 45 |
return f() |
| 46 |
} |