Created
May 26, 2026 19:58
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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