40 lines
738 B
Go
40 lines
738 B
Go
|
|
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...)
|
||
|
|
}
|