43 lines
813 B
Go
43 lines
813 B
Go
package module
|
|
|
|
//go:generate go run github.com/mailru/easyjson/easyjson -all hello_world.go
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"golang.org/x/exp/slog"
|
|
|
|
sdk "code.icb4dc0.de/buildr/wasi-module-sdk-go"
|
|
)
|
|
|
|
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", slog.String("name", h.Name))
|
|
|
|
if f, err := os.CreateTemp(ctx.OutDir(), "hello_world.*.txt"); err != nil {
|
|
return err
|
|
} else if err = f.Close(); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println("Hello world")
|
|
_, _ = fmt.Fprint(ctx.StdOut(), "Hello world via pipeline")
|
|
|
|
return nil
|
|
}
|
|
|
|
func (HelloWorld) Category() sdk.Category {
|
|
return sdk.CategoryTask
|
|
}
|
|
|
|
func (HelloWorld) Type() string {
|
|
return "hello_world"
|
|
}
|