sshpoke/internal/server/driver/null/driver.go

46 lines
1.1 KiB
Go

package null
import (
"context"
"github.com/Neur0toxine/sshpoke/internal/config"
"github.com/Neur0toxine/sshpoke/internal/server/driver/base"
"github.com/Neur0toxine/sshpoke/pkg/dto"
)
// Null driver only logs container events to debug log. It is used when user provides invalid driver type.
// You can use it directly, but it won't do anything, so... why bother?
type Null struct {
base.Base
}
func New(ctx context.Context, name string, params config.DriverParams) (base.Driver, error) {
return &Null{
Base: base.New(ctx, name),
}, nil
}
func (d *Null) Handle(event dto.Event) error {
d.Log().Debugw("handling event with null driver", "serverName", d.Name(), "event", event)
switch event.Type {
case dto.EventStart:
d.PushEventStatus(dto.EventStatus{
Type: dto.EventStart,
ID: event.Container.ID,
Domain: "https://" + event.Container.ID + "null.dev",
})
case dto.EventStop, dto.EventShutdown:
d.PushEventStatus(dto.EventStatus{
Type: event.Type,
ID: event.Container.ID,
})
}
return nil
}
func (d *Null) Driver() config.DriverType {
return config.DriverNull
}
func (d *Null) WaitForShutdown() {}