wasi-module-sdk-go/api.go

71 lines
1.1 KiB
Go
Raw Normal View History

2023-05-08 13:21:31 +00:00
package sdk
import (
"context"
"fmt"
"golang.org/x/exp/slog"
"io"
"time"
)
type Category string
func (t Category) String() string {
return string(t)
}
func (t Category) GroupName() string {
return fmt.Sprintf("%ss", t)
}
const (
CategoryTool Category = "tool"
CategoryTask Category = "task"
CategoryBuild Category = "build"
CategoryPackage Category = "package"
)
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 Module interface {
Execute(ctx ExecutionContext) error
Category() Category
Type() string
}
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()
}