72 lines
1.2 KiB
Go
72 lines
1.2 KiB
Go
package sdk
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/mailru/easyjson"
|
|
"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 {
|
|
easyjson.Unmarshaler
|
|
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()
|
|
}
|