You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-07-17 01:12:45 +02:00
Document functional options (#1899)
* Document functional options * Update CONTRIBUTING.md Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> * Update CONTRIBUTING.md Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com> Co-authored-by: Anthony Mirabella <a9@aneurysm9.com>
This commit is contained in:
@ -294,6 +294,23 @@ func WithMyType(t MyType) Option {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Functional Options
|
||||||
|
|
||||||
|
```go
|
||||||
|
type optionFunc func(*config)
|
||||||
|
|
||||||
|
func (fn optionFunc) apply(c *config) {
|
||||||
|
fn(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMyType sets t as MyType.
|
||||||
|
func WithMyType(t MyType) Option {
|
||||||
|
return optionFunc(func(c *config) {
|
||||||
|
c.MyType = t
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### Instantiation
|
#### Instantiation
|
||||||
|
|
||||||
Using this configuration pattern to configure instantiation with a `NewT`
|
Using this configuration pattern to configure instantiation with a `NewT`
|
||||||
|
Reference in New Issue
Block a user