/
config.go
44 lines (33 loc) · 848 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package sink
import "time"
// Config holds configuration for the sink.
type Config[I, O any] struct {
MaxItemsForBatching int
MaxTimeoutForBatching time.Duration
Logger Logger
AddPoolSize int
CallbackPoolSize int
ExpensivePoolSize int
ExpensiveOperation expensiveOperation[I, O]
}
func validateConfig[I, O any](config Config[I, O]) error {
if config.MaxItemsForBatching < 1 {
return ErrInvalidMaxItemsForBatching
}
if config.ExpensiveOperation == nil {
return ErrNilExpensiveOperation
}
if config.MaxTimeoutForBatching < time.Millisecond {
return ErrInvalidMaxTimeoutForBatching
}
if config.AddPoolSize < 1 {
return ErrInvalidAddPoolSize
}
if config.CallbackPoolSize < 1 {
return ErrInvalidCallbackPoolSize
}
if config.ExpensivePoolSize < 1 {
return ErrInvalidExpensivePoolSize
}
return nil
}