# wasm-example **Repository Path**: chanterchen/wasm-example ## Basic Information - **Project Name**: wasm-example - **Description**: go编译wasm示例 - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-07 - **Last Updated**: 2026-04-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Go WebAssembly 示例 本项目演示了如何使用 Go 语言编写 WebAssembly 程序,并在浏览器或 Node.js 环境中运行。 ## 功能简介 - **hello** 函数:返回经典的 "Hello, World!" 问候语 - 支持在现代浏览器中运行 WebAssembly 模块 - 支持在 Node.js 环境中运行 ## 环境要求 - Go 1.17 或更高版本 - 支持 WebAssembly 的现代浏览器 或 Node.js ## 构建与运行 ### 浏览器环境 1. 构建 WASM 模块: ```bash make # 或者手动执行: go build -o hello.wasm main.go ``` 2. 启动本地服务器(如使用 Go http.server): ```bash go run -exec=go run main.go # 或者使用其他 HTTP 服务器托管 index.html ``` 3. 在浏览器中访问 `index.html` ### Node.js 环境 ```bash node wasm_exec_node.js ``` ## 项目结构 ``` . ├── main.go # Go 源代码 ├── hello.wasm # 编译后的 WebAssembly 文件 ├── index.html # HTML 入口页面 ├── wasm_exec.js # 浏览器端 WebAssembly 加载器 ├── wasm_exec_node.js # Node.js 端加载器 ├── makefile # 构建脚本 ├── go.mod # Go 模块定义 └── LICENSE # 许可证 ``` ## 许可证 MIT License