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

55 lines
1.0 KiB
Go

package logotel
import (
"git.blauwelle.com/go/crate/log/logsdk/logjson"
)
func newConfig(opts ...Option) *config {
cfg := defaultConfig()
for _, opt := range opts {
opt.apply(cfg)
}
if !cfg.hasPool {
cfg.bytesBufferPool = logjson.DefaultBytesBufferPool
}
return cfg
}
func defaultConfig() *config {
return &config{
hasPool: false,
defaultSpan: false,
}
}
// WithBufferPool 指定缓冲池
func WithBufferPool(pool logjson.BytesBufferPool) Option {
return optionFunc(func(cfg *config) {
cfg.bytesBufferPool = pool
cfg.hasPool = true
})
}
// WithDefaultSpan 设置当 span 没有在记录时创建新 span
func WithDefaultSpan(defaultSpan bool) Option {
return optionFunc(func(cfg *config) {
cfg.defaultSpan = defaultSpan
})
}
// Option 配置 Processor
type Option interface {
apply(cfg *config)
}
type config struct {
bytesBufferPool logjson.BytesBufferPool
hasPool bool
defaultSpan bool
}
type optionFunc func(cfg *config)
func (fn optionFunc) apply(cfg *config) {
fn(cfg)
}