mirror of
https://github.com/hanzoai/goa.git
synced 2026-09-30 21:55:10 +00:00
One Module/Engine interface with a JSON-in/JSON-out calling convention runs four pure-Go engines behind a Pool that makes single-threaded interpreters serve requests as parallel goroutines: native plain Go handlers, zero overhead goja + esbuild JavaScript and TypeScript (TS transpiled to ES2020) gpython Python, no cgo and no GIL -> true goroutine parallelism wazero Rust/WASM via a trivial string ABI Services mount from a manifest (lang + source + routes), so any Go, Python, Rust or JS backend collapses into a single static CGO_ENABLED=0 binary served on the zip/gofiber app. A Go-backed json stdlib shim lets Python backends keep importing the real module names while running at Go speed. Examples and tests cover every engine; the Rust guest is a real wasm32 fixture exercised end to end.
32 lines
826 B
Go
32 lines
826 B
Go
// Command serve loads every *.manifest.json in the examples directory and
|
|
// serves the polyglot services on :8080 — Python (gpython) and TypeScript
|
|
// (goja) handlers running as goroutines inside one static Go binary.
|
|
//
|
|
// go run ./examples/serve
|
|
// curl -s localhost:8080/v1/hello-py/greet -d '{"name":"ada"}'
|
|
// curl -s localhost:8080/v1/hello-ts/greet -d '{"name":"ada"}'
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/hanzoai/goa"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
services, err := goa.LoadDir(ctx, "examples")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
mux := http.NewServeMux()
|
|
for _, s := range services {
|
|
s.Mount(mux)
|
|
log.Printf("mounted %s at %s (%d routes)", s.Name, s.Prefix, len(s.Routes))
|
|
}
|
|
log.Println("listening on :8080")
|
|
log.Fatal(http.ListenAndServe(":8080", mux))
|
|
}
|