sshpoke/internal/server/driver/nil/driver.go

46 lines
1.1 KiB
Go
Raw Normal View History

package nil
2023-11-17 20:39:00 +03:00
import (
"context"
"github.com/Neur0toxine/sshpoke/internal/config"
"github.com/Neur0toxine/sshpoke/internal/server/driver/base"
"github.com/Neur0toxine/sshpoke/pkg/dto"
2023-11-17 20:39:00 +03:00
)
// Nil driver only logs container events to debug log. It is used when user provides invalid driver type.
2023-11-17 20:39:00 +03:00
// You can use it directly, but it won't do anything, so... why bother?
type Nil struct {
base.Base
2023-11-17 20:39:00 +03:00
}
func New(ctx context.Context, name string, params config.DriverParams) (base.Driver, error) {
return &Nil{
Base: base.New(ctx, name),
}, nil
2023-11-17 20:39:00 +03:00
}
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,
})
}
2023-11-17 20:39:00 +03:00
return nil
}
func (d *Nil) Driver() config.DriverType {
return config.DriverNil
2023-11-17 20:39:00 +03:00
}
func (d *Nil) WaitForShutdown() {}