| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package internal // import "go.opentelemetry.io/collector/config/confighttp/internal" |
| 5 |
|
| 6 |
import ( |
| 7 |
"io" |
| 8 |
"net/http" |
| 9 |
|
| 10 |
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" |
| 11 |
) |
| 12 |
|
| 13 |
// ToServerOptions has options that change the behavior of the HTTP server |
| 14 |
// returned by ServerConfig.ToServer(). |
| 15 |
type ToServerOptions struct { |
| 16 |
ErrHandler func(w http.ResponseWriter, r *http.Request, errorMsg string, statusCode int) |
| 17 |
Decoders map[string]func(body io.ReadCloser) (io.ReadCloser, error) |
| 18 |
OtelhttpOpts []otelhttp.Option |
| 19 |
} |
| 20 |
|
| 21 |
func (tso *ToServerOptions) Apply(opts ...ToServerOption) { |
| 22 |
for _, o := range opts { |
| 23 |
o.apply(tso) |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// ToServerOption is an option to change the behavior of the HTTP server |
| 28 |
// returned by ServerConfig.ToServer(). |
| 29 |
type ToServerOption interface { |
| 30 |
apply(*ToServerOptions) |
| 31 |
} |
| 32 |
|
| 33 |
// ToServerOptionFunc converts a function into ToServerOption interface. |
| 34 |
type ToServerOptionFunc func(*ToServerOptions) |
| 35 |
|
| 36 |
func (of ToServerOptionFunc) apply(e *ToServerOptions) { |
| 37 |
of(e) |
| 38 |
} |