41 lines
788 B
Go
41 lines
788 B
Go
package module
|
|
|
|
//go:generate go run -mod=mod github.com/mailru/easyjson/easyjson -all hello_world.go
|
|
|
|
import (
|
|
sdk "code.icb4dc0.de/buildr/wasi-module-sdk-go"
|
|
"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"
|
|
}
|