74 lines
1.3 KiB
Go
74 lines
1.3 KiB
Go
package sdk
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log/slog"
|
|
"time"
|
|
|
|
rpcv1 "code.icb4dc0.de/buildr/wasi-module-sdk-go/protocol/generated/rpc/v1"
|
|
)
|
|
|
|
type Category = rpcv1.Category
|
|
|
|
const (
|
|
CategoryTool = rpcv1.Category_CategoryTool
|
|
CategoryTask = rpcv1.Category_CategoryTask
|
|
CategoryBuild = rpcv1.Category_CategoryBuild
|
|
CategoryPackage = rpcv1.Category_CategoryPackage
|
|
)
|
|
|
|
type StateMetadata struct {
|
|
ModifiedAt time.Time
|
|
TTL *time.Time
|
|
}
|
|
|
|
type ExecutionContext interface {
|
|
context.Context
|
|
WorkingDir() string
|
|
OutDir() string
|
|
BinariesDir() string
|
|
StdOut() io.Writer
|
|
StdErr() io.Writer
|
|
Logger() *slog.Logger
|
|
GetState(ctx context.Context, key string) ([]byte, StateMetadata, error)
|
|
SetState(ctx context.Context, key string, value []byte) error
|
|
}
|
|
|
|
type TaskSpec[T Module] struct {
|
|
Module T
|
|
ModuleName string
|
|
Container *rpcv1.ContainerSpec
|
|
OutputDir string
|
|
}
|
|
|
|
type Module interface {
|
|
Execute(ctx ExecutionContext) error
|
|
Category() Category
|
|
Type() string
|
|
}
|
|
|
|
type Helper interface {
|
|
Help() Help
|
|
}
|
|
|
|
type BinaryNamer interface {
|
|
BinaryName() string
|
|
}
|
|
|
|
type ToolModule interface {
|
|
Module
|
|
BinaryNamer
|
|
}
|
|
|
|
type Factory interface {
|
|
Create() Module
|
|
}
|
|
|
|
var _ Factory = (*ModuleFactoryFunc)(nil)
|
|
|
|
type ModuleFactoryFunc func() Module
|
|
|
|
func (f ModuleFactoryFunc) Create() Module {
|
|
return f()
|
|
}
|