Skip to content

Instantly share code, notes, and snippets.

@copyleftdev
Created May 26, 2026 19:58
Show Gist options
  • Select an option

  • Save copyleftdev/55a3de6ea50051fa53beb8db08b28d57 to your computer and use it in GitHub Desktop.

Select an option

Save copyleftdev/55a3de6ea50051fa53beb8db08b28d57 to your computer and use it in GitHub Desktop.
micro-containers: WASI preview1 variant — JSON to stdout (no net/http in wasip1)
// WASI preview1 target — compiled with GOOS=wasip1 GOARCH=wasm.
// net/http is not available in wasip1; this demonstrates env access,
// stdout, and runtime introspection inside a WASM container.
// The wasi-http proposal (https://github.com/WebAssembly/wasi-http)
// will bring full HTTP support to WASI in a future Go release.
package main
import (
"encoding/json"
"fmt"
"os"
"runtime"
)
func main() {
name := "wasm"
if v := os.Getenv("RUNTIME_NAME"); v != "" {
name = v
}
payload := map[string]string{
"status": "ok",
"runtime": name,
"go_version": runtime.Version(),
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
if err := enc.Encode(payload); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment