初始化缓存管理器
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
)
|
||||
|
||||
type managerOptions struct {
|
||||
logger ILogger
|
||||
}
|
||||
|
||||
func defaultManagerOptions() *managerOptions {
|
||||
return &managerOptions{
|
||||
logger: &DefLogger{},
|
||||
}
|
||||
}
|
||||
|
||||
type OptionFunc func(*managerOptions)
|
||||
|
||||
func WithLogger(log ILogger) OptionFunc {
|
||||
return func(o *managerOptions) {
|
||||
o.logger = log
|
||||
}
|
||||
}
|
||||
|
||||
type ILogger interface {
|
||||
Infof(ctx context.Context, format string, args ...any)
|
||||
Errorf(ctx context.Context, format string, args ...any)
|
||||
}
|
||||
|
||||
type DefLogger struct{}
|
||||
|
||||
func (l *DefLogger) Infof(ctx context.Context, format string, args ...any) {
|
||||
log.Printf("[info]"+format, args...)
|
||||
}
|
||||
|
||||
func (l *DefLogger) Errorf(ctx context.Context, format string, args ...any) {
|
||||
log.Printf("[error]"+format, args...)
|
||||
}
|
||||
Reference in New Issue
Block a user