mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-02 08:52:21 +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:
parent
cabf0c0782
commit
ae85fab3c3
@ -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
|
||||
|
||||
Using this configuration pattern to configure instantiation with a `NewT`
|
||||
|
Loading…
Reference in New Issue
Block a user