{"id":13645836,"url":"https://github.com/erning/gorun","last_synced_at":"2025-12-15T12:09:47.135Z","repository":{"id":4629371,"uuid":"5773650","full_name":"erning/gorun","owner":"erning","description":"gorun is a tool enabling one to put a \"bang line\" in the source code of a Go program to run it, or to run such a source code file explicitly. It was created in an attempt to make experimenting with Go more appealing to people used to Python and similar languages which operate most visibly with source code.","archived":false,"fork":false,"pushed_at":"2023-03-15T02:37:41.000Z","size":60,"stargazers_count":971,"open_issues_count":3,"forks_count":70,"subscribers_count":44,"default_branch":"master","last_synced_at":"2024-11-09T19:39:41.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://wiki.ubuntu.com/gorun","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-09-12T01:49:28.000Z","updated_at":"2024-11-01T17:24:20.000Z","dependencies_parsed_at":"2023-07-06T20:33:59.210Z","dependency_job_id":null,"html_url":"https://github.com/erning/gorun","commit_stats":{"total_commits":48,"total_committers":11,"mean_commits":4.363636363636363,"dds":0.6041666666666667,"last_synced_commit":"02445e31634ff49849d1afa7401c34448e3ff64b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erning%2Fgorun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erning%2Fgorun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erning%2Fgorun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erning%2Fgorun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erning","download_url":"https://codeload.github.com/erning/gorun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250100429,"owners_count":21374936,"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":[],"created_at":"2024-08-02T01:02:43.035Z","updated_at":"2025-12-15T12:09:41.816Z","avatar_url":"https://github.com/erning.png","language":"Go","funding_links":[],"categories":["Misc","Improved `go run`","Go"],"sub_categories":[],"readme":"# gorun\n\n## What is it?\ngorun is a tool enabling one to put a \"bang line\" in the source code of a Go program to run it, or to run such a source code file explicitly. It was created in an attempt to make experimenting with Go more appealing to people used to Python and similar languages which operate most visibly with source code.\n\n## Example\nAs an example, copy the following content to a file named \"hello.go\" (or \"hello\", if you prefer):\n\n```go\n#!/usr/bin/env gorun\n\npackage main\n\nfunc main() {\n    println(\"Hello world!\")\n}\n```\n\nOr if you like your file to be compatible with other tools, use:\n\n```go\n/// 2\u003e/dev/null ; gorun \"$0\" \"$@\" ; exit $?\n\npackage main\n\nfunc main() {\n    println(\"Hello world!\")\n}\n```\n\nThe above is a valid Go source file, and works normally in, e.g., your IDE. Note that the reason this hack is needed is because Go deliberately does not support `#!` as a comment syntax because they [like](https://groups.google.com/g/golang-nuts/c/iGHWoUQFHjg/discussion) making your tradeoffs for you.\n\nThen, simply run it:\n\n```\n$ chmod +x hello.go\n$ ./hello.go\nHello world!\n```\n\n## Features\ngorun will:\n\n  * write files under a safe directory in $TMPDIR (or /tmp), so that the actual script location isn't touched (may be read-only)\n  * avoid races between parallel executions of the same file\n  * automatically clean up old compiled files that remain unused for some time (without races)\n  * replace the process rather than using a child\n  * pass arguments to the compiled application properly\n  * handle well GOROOT, GOROOT_FINAL and the location of the toolchain\n  * support embedded go.mod, go.sum and environment variables used for compiling - can ensure a repeatable build\n\n## Is it slow?\nNo, it's not, thanks to the Go (gc) compiler suite, which compiles code surprisingly fast.\n\nHere is a trivial/non-scientific comparison with Python:\n\n```\n$ time ./gorun hello.go\nHello world!\n./gorun hello.go  0.03s user 0.00s system 74% cpu 0.040 total\n\n$ time ./gorun hello.go\nHello world!\n./gorun hello.go  0.00s user 0.00s system 0% cpu 0.003 total\n\n$ time python -c 'print \"Hello world!\"'                                                        \nHello world!\npython -c 'print \"Hello world!\"'  0.01s user 0.00s system 63% cpu 0.016 total\n\n$ time python -c 'print \"Hello world!\"'\nHello world!\npython -c 'print \"Hello world!\"'  0.00s user 0.01s system 64% cpu 0.016 total\n```\n\nNote how the second run is significantly faster than the first one. This happens because a cached version of the file is used after the first compilation.\n\ngorun will correctly recompile the file whenever necessary.\n\nHere is a more sophisticated comparison via [hyperfine](https://github.com/sharkdp/hyperfine):\n\n`hyperfine --export-markdown hf.md --warmup 10 'gorun ./hello.go' './hello' \"python3 -c 'print(\\\"Hello world\\\")'\"`\n\n| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |\n|:---|---:|---:|---:|---:|\n| `gorun ./hello.go` | 9.3 ± 3.8 | 5.7 | 36.5 | 2.11 ± 1.43 |\n| `./hello` | 4.4 ± 2.4 | 1.1 | 17.4 | 1.00 |\n| `python3 -c 'print(\"Hello world\")'` | 42.2 ± 2.9 | 37.6 | 48.7 | 9.62 ± 5.26 |\n\n\n## Where are the compiled files kept?\nThey are kept under $TMPDIR (or tmp), in a directory named after the hostname and user id executing the file.\n\nYou can remove these files, but there's no reason to do this. These compiled files will be garbage collected by gorun itself after a while once they stop being used. This is done in a fast and safe way so that concurrently executing scripts will not fail to execute.\n\n## Ubuntu packages\nThere are Ubuntu packages available that include gorun:\n\n```\n$ sudo add-apt-repository ppa:gophers/go \n$ sudo apt-get update \n$ sudo apt-get install golang \n```\n\n## How to build and install gorun from source\nJust use \"go get\" as usual:\n\n**Option 1:** from Launchpad (requires [Bazaar](http://wiki.bazaar.canonical.com/)):\n\n```\n$ go get launchpad.net/gorun\n```\n\n**Option 2:** from Github (requires [Git](http://git-scm.com)):\n\n```\n$ go get github.com/erning/gorun\n```\n\n## Reporting bugs\nPlease report bugs at: https://launchpad.net/gorun\n\n## License\n\ngorun is licensed under the GPL.\n\nThis document is licensed under Creative Commons Attribution-ShareAlike 3.0 License.\n\n## Contact\nTo get in touch, send a message to gustavo.niemeyer@canonical.com\n\n## Repeatable builds\nTo protect against changing/different dependencies compiled with the script, it supports embedding \ngo.mod, go.sum contents and environment variables in the file as a comment. Fictitious example:\n    \n    // go.mod \u003e\u003e\u003e\n    // module github.com/a/b\n    // go 1.13\n    // require github.com/c/d v0.0.0-20200225084820-12345affa\n    // require mycompany.com/e/f v0.0.0-20200225084120-1849135\n    // \u003c\u003c\u003c go.mod\n    //\n    // go.env \u003e\u003e\u003e\n    // GOPRIVATE=mycompany.com\n    // GO111MODULE=on\n    // \u003c\u003c\u003c go.env\n    //\n    // go.sum \u003e\u003e\u003e\n    // github.com/c v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=\n    // \u003c\u003c\u003c go.sum\n    \n    package main\n    \n    import (\n    ...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferning%2Fgorun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferning%2Fgorun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferning%2Fgorun/lists"}