Documentation
¶
Overview ¶
Package generator creates TypeScript client code for Go WASM functions.
Two modes are supported:
- Sync mode: class that calls globalThis functions directly
- Worker mode: class that communicates via Web Worker
Go functions returning (T, error) automatically throw in TypeScript using the __error field convention defined by ErrorFieldName.
Index ¶
- Constants
- func Generate(parsed *parser.ParsedFile) string
- func GenerateClass(functions []parser.GoFunction, className string) string
- func GenerateClassMethod(fn parser.GoFunction) string
- func GenerateClient(parsed *parser.ParsedFile) string
- func GenerateFunctionParams(params []parser.GoParameter) string
- func GenerateGoBindings(parsed *parser.ParsedFile, workerMode bool) string
- func GenerateHeader(packageName string) string
- func GenerateInterfaceForFunction(fn parser.GoFunction, types map[string]*parser.GoType) string
- func GenerateWorker(wasmPath string) string
- func GenerateWorkerClassMethod(fn parser.GoFunction) string
- func InterfaceName(funcName string) string
Constants ¶
const ErrorFieldName = "__error"
ErrorFieldName is the JSON field used to pass Go errors through the WASM boundary. When a Go function returns (T, error), the generated binding returns map[string]interface{}{ErrorFieldName: err.Error()} on error. The TypeScript client checks for this field and throws it as a JavaScript Error.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
func Generate(parsed *parser.ParsedFile) string
Generate creates TypeScript class-based client for sync mode. This generates a class that wraps globalThis function calls.
func GenerateClass ¶
func GenerateClass(functions []parser.GoFunction, className string) string
GenerateClass creates the TypeScript class with sync methods.
func GenerateClassMethod ¶
func GenerateClassMethod(fn parser.GoFunction) string
GenerateClassMethod creates a single instance method that calls globalThis.
func GenerateClient ¶
func GenerateClient(parsed *parser.ParsedFile) string
GenerateClient creates client.ts with a class-based API for worker mode.
func GenerateFunctionParams ¶
func GenerateFunctionParams(params []parser.GoParameter) string
GenerateFunctionParams formats the parameter list as TypeScript.
func GenerateGoBindings ¶
func GenerateGoBindings(parsed *parser.ParsedFile, workerMode bool) string
GenerateGoBindings generates Go wrapper code for WASM export. workerMode determines whether callbacks use postMessage-based invocation (true) or direct JS function invocation (false).
func GenerateHeader ¶
GenerateHeader creates the file header comment.
func GenerateInterfaceForFunction ¶
GenerateInterfaceForFunction creates an exported interface if the function returns a struct. Returns empty string if the function doesn't return a struct type.
func GenerateWorker ¶
GenerateWorker creates worker.js content that runs Go WASM in a Web Worker. The wasmPath parameter specifies the path to the WASM file (e.g., "module.wasm").
func GenerateWorkerClassMethod ¶
func GenerateWorkerClassMethod(fn parser.GoFunction) string
GenerateWorkerClassMethod creates a single async instance method for worker mode.
func InterfaceName ¶
InterfaceName converts a function name to a result interface name. e.g., "formatUser" -> "FormatUserResult", "getInfo" -> "GetInfoResult"
Types ¶
This section is empty.