code.icb4dc0.de/buildr/wasi-module-sdk-go@v0.0.0-20230524201105-cc52d195017b/api.go (about) 1 package sdk 2 3 import ( 4 "context" 5 "fmt" 6 "github.com/mailru/easyjson" 7 "golang.org/x/exp/slog" 8 "io" 9 "time" 10 ) 11 12 type Category string 13 14 func (t Category) String() string { 15 return string(t) 16 } 17 18 func (t Category) GroupName() string { 19 return fmt.Sprintf("%ss", t) 20 } 21 22 const ( 23 CategoryTool Category = "tool" 24 CategoryTask Category = "task" 25 CategoryBuild Category = "build" 26 CategoryPackage Category = "package" 27 ) 28 29 type StateMetadata struct { 30 ModifiedAt time.Time 31 TTL *time.Time 32 } 33 34 type ExecutionContext interface { 35 context.Context 36 WorkingDir() string 37 OutDir() string 38 BinariesDir() string 39 StdOut() io.Writer 40 StdErr() io.Writer 41 Logger() *slog.Logger 42 GetState(ctx context.Context, key string) ([]byte, StateMetadata, error) 43 SetState(ctx context.Context, key string, value []byte) error 44 } 45 46 type Module interface { 47 easyjson.Unmarshaler 48 Execute(ctx ExecutionContext) error 49 Category() Category 50 Type() string 51 } 52 53 type BinaryNamer interface { 54 BinaryName() string 55 } 56 57 type ToolModule interface { 58 Module 59 BinaryNamer 60 } 61 62 type Factory interface { 63 Create() Module 64 } 65 66 var _ Factory = (*ModuleFactoryFunc)(nil) 67 68 type ModuleFactoryFunc func() Module 69 70 func (f ModuleFactoryFunc) Create() Module { 71 return f() 72 }