You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crate/logotel/option.go

44 lines
775 B
Go

package logotel
import "git.blauwelle.com/go/crate/synchelper"
func newConfig(opts ...Option) *config {
cfg := defaultConfig()
for _, opt := range opts {
opt.apply(cfg)
}
if !cfg.hasPool {
cfg.bufferPool = synchelper.NewBytesBufferPool(512, 4096)
}
return cfg
}
func defaultConfig() *config {
return &config{
hasPool: false,
}
}
// WithBufferPool 指定缓冲池
func WithBufferPool(pool synchelper.BytesBufferPool) Option {
return optionFunc(func(cfg *config) {
cfg.bufferPool = pool
cfg.hasPool = true
})
}
// Option 配置 Processor
type Option interface {
apply(cfg *config)
}
type config struct {
bufferPool synchelper.BytesBufferPool
hasPool bool
}
type optionFunc func(cfg *config)
func (fn optionFunc) apply(cfg *config) {
fn(cfg)
}