2023-05-08 13:21:31 +00:00
|
|
|
package module
|
|
|
|
|
|
|
|
//go:generate go run -mod=mod github.com/mailru/easyjson/easyjson -all hello_world.go
|
|
|
|
|
|
|
|
import (
|
2023-05-18 16:21:44 +00:00
|
|
|
sdk "code.icb4dc0.de/buildr/wasi-module-sdk-go"
|
2023-05-08 13:21:31 +00:00
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ sdk.Module = (*HelloWorld)(nil)
|
|
|
|
|
|
|
|
type HelloWorld struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h HelloWorld) Execute(ctx sdk.ExecutionContext) error {
|
|
|
|
logger := ctx.Logger()
|
|
|
|
|
|
|
|
logger.Info("Executing hello world")
|
|
|
|
|
|
|
|
val, _, err := ctx.GetState(ctx, "hello")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ctx.SetState(ctx, "state", []byte(`{"hello":"world"}`)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Info("Got value from state", slog.String("value", string(val)))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (HelloWorld) Category() sdk.Category {
|
|
|
|
return sdk.CategoryTask
|
|
|
|
}
|
|
|
|
|
|
|
|
func (HelloWorld) Type() string {
|
|
|
|
return "hello_world"
|
|
|
|
}
|