@@ -160,7 +160,7 @@ functions using a functional-option argument passed to
160
160
func WithLogs (createLogs CreateLogsFunc , sl component .StabilityLevel ) FactoryOption {
161
161
return factoryOptionFunc (func (o *factoryImpl, cfgType component.Type ) {
162
162
o.CreateLogsFunc = createLogs
163
- o.LogsStabilityFunc = sl.Self
163
+ o.LogsStabilityFunc = sl.Self // See (5) below
164
164
})
165
165
}
166
166
@@ -218,20 +218,19 @@ func NewRateLimiterWithExtraFeature(rf ReserveRateFunc, ef ExtraFeatureFunc) Rat
218
218
### 5. Constant-value Function Implementations
219
219
220
220
For types defined by simple values, especially for enumerated types,
221
- define a ` Self() ` method to act as the corresponding functional
222
- constant:
221
+ define a ` Self() ` method to act as the corresponding value:
223
222
224
223
``` go
225
224
// Self returns itself.
226
- func (t Type ) Self () Type {
225
+ func (t Config ) Self () Config {
227
226
return t
228
227
}
229
228
230
- // TypeFunc is ...
231
- type TypeFunc func () Type
229
+ // ConfigFunc is ...
230
+ type ConfigFunc func () Config
232
231
233
- // Type gets the type of the component created by this factory.
234
- func (f TypeFunc ) Type () Type {
232
+ // Config gets the type of the component created by this factory.
233
+ func (f ConfigFunc ) Config () Config {
235
234
if f == nil {
236
235
}
237
236
return f ()
@@ -243,24 +242,22 @@ For example, we can decompose, modify, and recompose a
243
242
constant-valued Type and Config functions:
244
243
245
244
``` go
246
- // Construct a factory, get its default default Config:
247
- originalFactory := somepackage. NewFactory ()
248
- cfg := originalFactory. CreateDefaultConfig ()
249
-
250
- // ... Modify the config object somehow
251
-
252
- // Pass cfg.Self as the default config function,
253
- // return a new factory using the modified config.
254
- return NewFactoryImpl (factory. Type (). Self , cfg. Self )
245
+ // Copy a factory from somepackage, modify its default config.
246
+ func modifiedFactory () Factory {
247
+ original := somepackage. NewFactory ()
248
+ cfg := original. CreateDefaultConfig ()
249
+
250
+ // ... Modify the config object somehow,
251
+ // pass cfg.Self as the default config function.
252
+ return component. NewFactory (original. Type , cfg. Self )
253
+ }
255
254
```
256
255
257
256
## Examples
258
257
259
- ### Flexibility and Composition
260
-
261
- This pattern enables composition scenarios by making it easy to
262
- compose and decompose interface values. For example, to wrap a
263
- ` receiver.Factory ` with a limiter of some sort:
258
+ This pattern enables composition by making it easy to compose and
259
+ decompose interface values. For example, to wrap a ` receiver.Factory `
260
+ with a limiter of some sort:
264
261
265
262
``` go
266
263
// Transform existing factories with cross-cutting concerns
0 commit comments