{"id":13366486,"url":"https://github.com/Gopherjs/Gopherjs","last_synced_at":"2025-03-12T18:31:00.957Z","repository":{"id":10297796,"uuid":"12418999","full_name":"gopherjs/gopherjs","owner":"gopherjs","description":"A compiler from Go to JavaScript for running Go code in a browser","archived":false,"fork":false,"pushed_at":"2024-10-16T22:19:01.000Z","size":6690,"stargazers_count":12713,"open_issues_count":198,"forks_count":567,"subscribers_count":243,"default_branch":"master","last_synced_at":"2024-10-19T18:46:31.607Z","etag":null,"topics":["compiler","go","golang","hacktoberfest","javascript"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mightybyte/map-syntax","license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gopherjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-27T22:23:58.000Z","updated_at":"2024-10-19T18:31:48.000Z","dependencies_parsed_at":"2023-07-13T09:24:23.776Z","dependency_job_id":"767031e7-f933-4173-a050-6c6dab67932e","html_url":"https://github.com/gopherjs/gopherjs","commit_stats":{"total_commits":2520,"total_committers":75,"mean_commits":33.6,"dds":0.3682539682539683,"last_synced_commit":"4dc2318893eef2b11359d1e0d8cebf687e8d98f1"},"previous_names":["neelance/gopherjs"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gopherjs%2Fgopherjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gopherjs%2Fgopherjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gopherjs%2Fgopherjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gopherjs%2Fgopherjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gopherjs","download_url":"https://codeload.github.com/gopherjs/gopherjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309828,"owners_count":16795818,"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","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":["compiler","go","golang","hacktoberfest","javascript"],"created_at":"2024-07-30T00:01:25.523Z","updated_at":"2024-10-24T11:30:19.151Z","avatar_url":"https://github.com/gopherjs.png","language":"Go","readme":"## GopherJS - A compiler from Go to JavaScript\n\n[![GoDoc](https://godoc.org/github.com/gopherjs/gopherjs/js?status.svg)](https://godoc.org/github.com/gopherjs/gopherjs/js)\n[![Sourcegraph](https://sourcegraph.com/github.com/gopherjs/gopherjs/-/badge.svg)](https://sourcegraph.com/github.com/gopherjs/gopherjs?badge)\n[![Github Actions CI](https://github.com/gopherjs/gopherjs/actions/workflows/ci.yaml/badge.svg)](https://github.com/gopherjs/gopherjs/actions/workflows/ci.yaml)\n\nGopherJS compiles Go code ([go.dev](https://go.dev/)) to pure JavaScript code. Its main purpose is to give you the opportunity to write front-end code in Go which will still run in all browsers.\n\n### Help us make GopherJS better!\n\n- ⤴️ **Help us make better decisions by filling a quick 15-question [GopherJS user survey](https://forms.gle/WEjZqZaPxTxjD9YP8)**.\n- 📢 Report and discuss [issues](https://github.com/gopherjs/gopherjs/issues).\n- 🎓 Share your knowledge and experience through [articles](https://github.com/gopherjs/gopherjs/wiki/Community-Tutorials-and-Blogs) and [documentation](https://github.com/gopherjs/gopherjs/tree/master/doc).\n- 🛠️ Write GopherJS [bindings](https://github.com/gopherjs/gopherjs/wiki/Bindings) for other libraries or [contribute](https://github.com/gopherjs/gopherjs/wiki/Developer-Guidelines) to GopherJS itself.\n\n### What's new?\n\n- 2024-02-24: Go 1.19 support is [available](https://github.com/gopherjs/gopherjs/releases/tag/v1.19.0-beta1)!\n- 2022-08-18: Go 1.18 support is [available](https://github.com/gopherjs/gopherjs/releases/tag/v1.18.0-beta2%2Bgo1.18.5)!\n- 2021-09-19: Go 1.17 support is available!\n- 2021-08-23: Go Modules are now fully supported.\n- 2021-06-19: Complete `syscall/js` package implementation compatible with the upstream Go 1.16.\n- 2021-04-04: **Go 1.16 is now officially supported!** 🎉 🎉 🎉\n\n### Playground\n\nGive GopherJS a try on the [GopherJS Playground](http://gopherjs.github.io/playground/).\n\n### What is supported?\n\nNearly everything, including Goroutines ([compatibility documentation](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md)). Performance is quite good in most cases, see [HTML5 game engine benchmark](https://ajhager.github.io/engi/demos/botmark.html). Cgo is not supported.\n\n### Installation and Usage\n\nGopherJS [requires Go 1.19 or newer](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md#go-version-compatibility). If you need an older Go\nversion, you can use an [older GopherJS release](https://github.com/gopherjs/gopherjs/releases).\n\nInstall GopherJS with `go install`:\n\n```\ngo install github.com/gopherjs/gopherjs@v1.19.0-beta1  # Or replace 'v1.19.0-beta1' with another version.\n```\n\nIf your local Go distribution as reported by `go version` is newer than Go 1.19, then you need to set the `GOPHERJS_GOROOT` environment variable to a directory that contains a Go 1.19 distribution. For example:\n\n```\ngo install golang.org/dl/go1.19.13@latest\ngo1.19.13 download\nexport GOPHERJS_GOROOT=\"$(go1.19.13 env GOROOT)\"  # Also add this line to your .profile or equivalent.\n```\n\nNow you can use `gopherjs build [package]`, `gopherjs build [files]` or `gopherjs install [package]` which behave similar to the `go` tool. For `main` packages, these commands create a `.js` file and `.js.map` source map in the current directory or in `$GOPATH/bin`. The generated JavaScript file can be used as usual in a website. Use `gopherjs help [command]` to get a list of possible command line flags, e.g. for minification and automatically watching for changes.\n\n`gopherjs` uses your platform's default `GOOS` value when generating code. Supported `GOOS` values are: `linux`, `darwin`. If you're on a different platform (e.g., Windows or FreeBSD), you'll need to set the `GOOS` environment variable to a supported value. For example, `GOOS=linux gopherjs build [package]`.\n\n_Note: GopherJS will try to write compiled object files of the core packages to your $GOROOT/pkg directory. If that fails, it will fall back to $GOPATH/pkg._\n\n#### gopherjs run, gopherjs test\n\nIf you want to use `gopherjs run` or `gopherjs test` to run the generated code locally, install Node.js 18 (or newer).\n\nOn supported `GOOS` platforms, it's possible to make system calls (file system access, etc.) available. See [doc/syscalls.md](https://github.com/gopherjs/gopherjs/blob/master/doc/syscalls.md) for instructions on how to do so.\n\n#### gopherjs serve\n\n`gopherjs serve` is a useful command you can use during development. It will start an HTTP server serving on \":8080\" by default, then dynamically compile your Go packages with GopherJS and serve them.\n\nFor example, navigating to `http://localhost:8080/example.com/user/project/` should compile and run the Go package `example.com/user/project`. The generated JavaScript output will be served at `http://localhost:8080/example.com/user/project/project.js` (the .js file name will be equal to the base directory name). If the directory contains `index.html` it will be served, otherwise a minimal `index.html` that includes `\u003cscript src=\"project.js\"\u003e\u003c/script\u003e` will be provided, causing the JavaScript to be executed. All other static files will be served too.\n\nRefreshing in the browser will rebuild the served files if needed. Compilation errors will be displayed in terminal, and in browser console. Additionally, it will serve $GOROOT and $GOPATH for sourcemaps.\n\nIf you include an argument, it will be the root from which everything is served. For example, if you run `gopherjs serve github.com/user/project` then the generated JavaScript for the package github.com/user/project/mypkg will be served at http://localhost:8080/mypkg/mypkg.js.\n\n#### Environment Variables\n\nThere are some GopherJS-specific environment variables:\n\n- `GOPHERJS_GOROOT` - if set, GopherJS uses this value as the default GOROOT\n  value, instead of using the system GOROOT as the default GOROOT value\n- `GOPHERJS_SKIP_VERSION_CHECK` - if set to true, GopherJS will not check\n  Go version in the GOROOT for compatibility with the GopherJS release. This\n  is primarily useful for testing GopherJS against unreleased versions of Go.\n\n### Performance Tips\n\n- Use the `-m` command line flag to generate minified code.\n- Apply gzip compression (https://en.wikipedia.org/wiki/HTTP_compression).\n- Use `int` instead of `(u)int8/16/32/64`.\n- Use `float64` instead of `float32`.\n\n### Community\n\n- [#gopherjs Channel on Gophers Slack](https://gophers.slack.com/messages/gopherjs/) (invites to Gophers Slack are available [here](http://blog.gopheracademy.com/gophers-slack-community/#how-can-i-be-invited-to-join:2facdc921b2310f18cb851c36fa92369))\n- [Bindings to JavaScript APIs and libraries](https://github.com/gopherjs/gopherjs/wiki/bindings)\n- [GopherJS Blog](https://medium.com/gopherjs)\n- [GopherJS on Twitter](https://twitter.com/GopherJS)\n- [Examples, tutorials and blogs](https://github.com/gopherjs/gopherjs/wiki/Community-Tutorials-and-Blogs)\n\n### Getting started\n\n#### Interacting with the DOM\n\nThe package `github.com/gopherjs/gopherjs/js` (see [documentation](https://godoc.org/github.com/gopherjs/gopherjs/js)) provides functions for interacting with native JavaScript APIs. For example the line\n\n```js\ndocument.write(\"Hello world!\");\n```\n\nwould look like this in Go:\n\n```go\njs.Global.Get(\"document\").Call(\"write\", \"Hello world!\")\n```\n\nYou may also want use the [DOM bindings](http://dominik.honnef.co/go/js/dom), the [jQuery bindings](https://github.com/gopherjs/jquery) (see [TodoMVC Example](https://github.com/gopherjs/todomvc)) or the [AngularJS bindings](https://github.com/wvell/go-angularjs). Those are some of the [bindings to JavaScript APIs and libraries](https://github.com/gopherjs/gopherjs/wiki/bindings) by community members.\n\n#### Providing library functions for use in other JavaScript code\n\nSet a global variable to a map that contains the functions:\n\n```go\npackage main\n\nimport \"github.com/gopherjs/gopherjs/js\"\n\nfunc main() {\n\tjs.Global.Set(\"pet\", map[string]interface{}{\n\t\t\"New\": New,\n\t})\n}\n\ntype Pet struct {\n\tname string\n}\n\nfunc New(name string) *js.Object {\n\treturn js.MakeWrapper(\u0026Pet{name})\n}\n\nfunc (p *Pet) Name() string {\n\treturn p.name\n}\n\nfunc (p *Pet) SetName(name string) {\n\tp.name = name\n}\n```\n\nFor more details see [Jason Stone's blog post](http://legacytotheedge.blogspot.de/2014/03/gopherjs-go-to-javascript-transpiler.html) about GopherJS.\n\n### Architecture\n\n#### General\n\nGopherJS emulates a 32-bit environment. This means that `int`, `uint` and `uintptr` have a precision of 32 bits. However, the explicit 64-bit integer types `int64` and `uint64` are supported.\n\nThe `GOOS` value of this environment is `js`, and the `GOARCH` value is `ecmascript`. You may use these values in build constraints when [writing platform-specific code](doc/compatibility.md#how-to-write-portable-code). (GopherJS 1.17 and older used `js` as the `GOARCH` value.)\n\n#### Application Lifecycle\n\nThe `main` function is executed as usual after all `init` functions have run. JavaScript callbacks can also invoke Go functions, even after the `main` function has exited. Therefore the end of the `main` function should not be regarded as the end of the application and does not end the execution of other goroutines.\n\nIn the browser, calling `os.Exit` (e.g. indirectly by `log.Fatal`) also does not terminate the execution of the program. For convenience, it calls `runtime.Goexit` to immediately terminate the calling goroutine.\n\n#### Goroutines\n\nGoroutines are fully supported by GopherJS. The only restriction is that you need to start a new goroutine if you want to use blocking code called from external JavaScript:\n\n```go\njs.Global.Get(\"myButton\").Call(\"addEventListener\", \"click\", func() {\n  go func() {\n    [...]\n    someBlockingFunction()\n    [...]\n  }()\n})\n```\n\nHow it works:\n\nJavaScript has no concept of concurrency (except web workers, but those are too strictly separated to be used for goroutines). Because of that, instructions in JavaScript are never blocking. A blocking call would effectively freeze the responsiveness of your web page, so calls with callback arguments are used instead.\n\nGopherJS does some heavy lifting to work around this restriction: Whenever an instruction is blocking (e.g. communicating with a channel that isn't ready), the whole stack will unwind (= all functions return) and the goroutine will be put to sleep. Then another goroutine which is ready to resume gets picked and its stack with all local variables will be restored.\n\n### GopherJS Development\n\nIf you're looking to make changes to the GopherJS compiler, see [Developer Guidelines](https://github.com/gopherjs/gopherjs/wiki/Developer-Guidelines) for additional developer information.\n","funding_links":[],"categories":["Go 编译器","Go 編譯器"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGopherjs%2FGopherjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGopherjs%2FGopherjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGopherjs%2FGopherjs/lists"}