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

51 lines
908 B
Go

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