Add a Go backend
Add Go routes with the @primate/go
module. Write handlers in Go; Primate
compiles them to WebAssembly and wires them like JS routes.
Make sure the Go executable is available in your
PATH
. Primate needs it to
compile your routes to WebAssembly.$ npm install @primate/go
TypeScriptconfig/app.ts
import go from "@primate/go";
import config from "primate/config";
export default config({ modules: [go()] });
Goroutes/index.go
package main
import (
"github.com/primate-run/go/core"
"github.com/primate-run/go/route"
)
var _ = route.Get(func(_ route.Request) any { return "Hello from Go" })
var _ = route.Post(func(_ route.Request) any { return core.Dict{"ok": true} })