{"id":20091428,"url":"https://github.com/junedev/go-fmt-wasm","last_synced_at":"2026-01-07T12:04:27.004Z","repository":{"id":44814972,"uuid":"415100695","full_name":"junedev/go-fmt-wasm","owner":"junedev","description":"Go format in the browser via WebAssembly","archived":false,"fork":false,"pushed_at":"2022-02-05T12:53:58.000Z","size":1107,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T23:28:37.507Z","etag":null,"topics":["formatting","golang","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://go-fmt-wasm.netlify.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-08T19:11:07.000Z","updated_at":"2022-10-31T17:00:23.000Z","dependencies_parsed_at":"2022-08-27T10:50:40.329Z","dependency_job_id":null,"html_url":"https://github.com/junedev/go-fmt-wasm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/junedev/go-fmt-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junedev%2Fgo-fmt-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junedev%2Fgo-fmt-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junedev%2Fgo-fmt-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junedev%2Fgo-fmt-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junedev","download_url":"https://codeload.github.com/junedev/go-fmt-wasm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junedev%2Fgo-fmt-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28235232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-07T02:00:05.975Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatting","golang","wasm","webassembly"],"created_at":"2024-11-13T16:32:08.981Z","updated_at":"2026-01-07T12:04:26.976Z","avatar_url":"https://github.com/junedev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go fmt in the browser via WebAssembly\n\n**DEMO: [go-fmt-wasm.netlify.app](https://go-fmt-wasm.netlify.app)**\n\nThis example uses the `go/format` package instead of compiling the `go fmt` command line tool because we don't have access to a file-system replacement out of the box in the browser which `go fmt` would need.\n\n[TinyGo](https://tinygo.org/) produces significantly smaller wasm files so we use that instead of the the standard Go compiler.  \nCompared to the standard Go version, the size of the wasm file drops from ~3MB to ~0,5MB (uncompressed).\nThe time from initial page load to when the format button can be pressed was reduced from ~1s to ~0.5s.\n\n## Creating the wasm file\n- Install tinygo, see https://tinygo.org/getting-started/install/\n- There is a custom wasm compile configuration needed (`wasm.json`) otherwise the stack size limit is too low to perform the formatting when there are more then ~100 (?) lines of code.\n  With the current setting in the config, 3000 lines of code can be formatted without problems (takes ~130ms).\n- Compile the Go code with `tinygo build -o format-go-code.wasm -target ./wasm.json -no-debug ./go/main.go`\n- To execute the wasm file from JS you also need some glue code. This code can also be found in your local go installation under `{path to your tinygo installation}/targets/wasm_exec.js`. This script needs to be imported as a script in your index.html. (On Linux, the tinygo directory is usually `/usr/local/lib/tinygo`.)\n- To avoid a memory leak, one function in the `wasm_exec.js` file needs to be replaced, see https://github.com/tinygo-org/tinygo/issues/1140#issuecomment-718145455\n\n## Using the wasm file\n- The glue code needs to be imported via `\u003cscript src=\"wasm_exec.js\"\u003e\u003c/script\u003e`.\n- The WASM file needs to be loaded, see index.html.\n- Afterwards, the \"exported\" function (`formatGoCode`) is available in JavaScript.\n\n## Error handling\n- If the formatting did not succeed, an empty string is returned. In that case, the result should not be used to replace the non-formatted code the user wrote.\n\n## Sources\n- https://tinygo.org/docs/guides/webassembly/\n- https://github.com/tinygo-org/tinygo/tree/release/src/examples/wasm/slices\n\n## Motivation\nThis is a standalone prototype for https://github.com/exercism/exercism/issues/5986.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunedev%2Fgo-fmt-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunedev%2Fgo-fmt-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunedev%2Fgo-fmt-wasm/lists"}