code.icb4dc0.de/buildr/wasi-module-sdk-go@v0.0.0-20230524201105-cc52d195017b/README.md (about)

     1  # Module SDK for Go
     2  
     3  This module provides glue code to implement a buildr WASI module easily and quickly.
     4  To implement a new buildr WASI module:
     5  
     6  1. Create a new Go module
     7  1. Reference this SDK (`go get -u code.icb4dc0.de/buildr/wasi-module-sdk-go`)
     8  1. create a `main.go` with an **empty** `main()` function
     9  1. implement the `sdk.Module` interface for your module
    10  1. implement an `init()` function that registers your module and the SDK's type registry
    11  1. compile the module e.g. with tinygo
    12  
    13  See also the [examples](./examples) directory to get started.
    14  
    15  ## Dependencies
    16  
    17  ### easyjson
    18  
    19  Right now the SDK depends on [easyjson](https://github.com/mailru/easyjson) to unmarshal the modules state as defined in the HCL configuration.
    20  The main reason for this is that the reflection support in TinyGo is limited and for instance `encoding/json` heavily depends on reflection.
    21  The SDK itself uses protobuf (vtprotobuf) to exchange data with the host without reflection but this is not generic enough to support every possibility of module configuration (e.g. `map<string, string>` would require extra encoding/decoding steps, same for `map<string, bytes`).
    22  Therefore, the SDK requires you to generate `easyjson` compatible unmarshal functions.
    23  
    24  ### slog
    25  
    26  *buildr* is using [`slog`](https://pkg.go.dev/golang.org/x/exp/slog) for logging (as soon as Go 1.21 is released it will move to the final version) and also the SDK is using it to allow modules log messages.
    27  When using the SDK there's nothing to be done except using the logger the is provided by the `ExecutionContext`.
    28  Alternatively it'd be possible to log to `STDOUT`/`STDERR` but keep in mind that logs written to these streams directly will be 'mixed' with the output of other processes.