46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package nil
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/config"
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/base"
|
|
"github.com/Neur0toxine/sshpoke/pkg/dto"
|
|
)
|
|
|
|
// Nil 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 Nil struct {
|
|
base.Base
|
|
}
|
|
|
|
func New(ctx context.Context, name string, params config.DriverParams) (base.Driver, error) {
|
|
return &Nil{
|
|
Base: base.New(ctx, name),
|
|
}, nil
|
|
}
|
|
|
|
func (d *Nil) Handle(event dto.Event) error {
|
|
d.Log().Debugw("handling event with nil 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 + ".nil.dev",
|
|
})
|
|
case dto.EventStop, dto.EventShutdown:
|
|
d.PushEventStatus(dto.EventStatus{
|
|
Type: event.Type,
|
|
ID: event.Container.ID,
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d *Nil) Driver() config.DriverType {
|
|
return config.DriverNil
|
|
}
|
|
|
|
func (d *Nil) WaitForShutdown() {}
|