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) }