47 lines
845 B
Go
47 lines
845 B
Go
package base
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/logger"
|
|
"github.com/Neur0toxine/sshpoke/pkg/dto"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type Base struct {
|
|
ctx context.Context
|
|
name string
|
|
log *zap.SugaredLogger
|
|
eventStatusCb EventStatusCallback
|
|
}
|
|
|
|
func New(ctx context.Context, name string) Base {
|
|
return Base{
|
|
ctx: ctx,
|
|
name: name,
|
|
log: logger.Default.With(zap.String("serverName", name)).Sugar(),
|
|
}
|
|
}
|
|
|
|
func (b *Base) SetEventStatusCallback(callback EventStatusCallback) {
|
|
b.eventStatusCb = callback
|
|
}
|
|
|
|
func (b *Base) PushEventStatus(status dto.EventStatus) {
|
|
if b.eventStatusCb != nil {
|
|
b.eventStatusCb(status)
|
|
}
|
|
}
|
|
|
|
func (b *Base) Context() context.Context {
|
|
return b.ctx
|
|
}
|
|
|
|
func (b *Base) Name() string {
|
|
return b.name
|
|
}
|
|
|
|
func (b *Base) Log() *zap.SugaredLogger {
|
|
return b.log
|
|
}
|