gorun

Differences between revisions 1 and 9 (spanning 8 versions)
Revision 1 as of 2011-03-11 22:02:10
Size: 2270
Editor: 201-40-152-213
Comment:
Revision 9 as of 2011-05-05 17:06:46
Size: 3096
Editor: 200-102-196-125
Comment:
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
The gorun project enables [[http://golang.org|Go]] programs to be used in a way
resembling so called "scripting" languages. To make use of it, simply put the
gorun command location at the top of a Go source file, and make it executable.
gorun is a tool enabling one to put a "bang line" in the source code
of a [[http://golang.org|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.
Line 13: Line 15:
{{{ {{{#!go
Line 32: Line 34:
== Features ==

gorun will:

  * write files under a safe directory in $TMPDIR (or /tmp), so that the actual script location isn't touched (may be read-only)
  * avoid races between parallel executions of the same file
  * automatically clean up old compiled files that remain unused for some time (without races)
  * replace the process rather than using a child
  * pass arguments to the compiled application properly
  * handle well GOROOT, GOROOT_FINAL and the location of the toolchain
Line 64: Line 76:
They are kept under the ~/.gorun directory. They are kept under $TMPDIR (or tmp), in a directory named after the hostname
and user id executing the file.
Line 67: Line 80:
files will be garbage collected by gorun itself when they stop being used.
This is done in a fast and safe way so that concurrently executing scripts
will not fail to execute.
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.
Line 72: Line 85:
== How to build and install gozk == == Ubuntu packages ==
Line 74: Line 87:
First, obtain the code from Launchpad: There are Ubuntu packages available that include gorun:
Line 76: Line 89:
$ bzr branch lp:gorun sudo add-apt-repository ppa:niemeyer/ppa
sudo apt-get update
sudo apt-get install golang
Line 79: Line 94:
Then, build it: == How to build and install gorun from source ==

Just use goinstall:
Line 81: Line 98:
$ cd gorun
$ make
$ goinstall launchpad.net/gorun

What is it?

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.

Example

As an example, copy the following content to a file named "hello.go" (or "hello", if you prefer):

#!/usr/bin/gorun

package main

func main() {
    println("Hello world!")
}

Then, simply run it:

$ chmod +x hello.go
$ ./hello.go
Hello world!

Features

gorun will:

  • write files under a safe directory in $TMPDIR (or /tmp), so that the actual script location isn't touched (may be read-only)
  • avoid races between parallel executions of the same file
  • automatically clean up old compiled files that remain unused for some time (without races)
  • replace the process rather than using a child
  • pass arguments to the compiled application properly
  • handle well GOROOT, GOROOT_FINAL and the location of the toolchain

Is it slow?

No, it's not, thanks to the Go (gc) compiler suite, which compiles code surprisingly fast.

Here is a trivial/non-scientific comparison with Python:

$ time ./gorun hello.go
Hello world!
./gorun hello.go  0.03s user 0.00s system 74% cpu 0.040 total

$ time ./gorun hello.go
Hello world!
./gorun hello.go  0.00s user 0.00s system 0% cpu 0.003 total

$ time python -c 'print "Hello world!"'                                                        
Hello world!
python -c 'print "Hello world!"'  0.01s user 0.00s system 63% cpu 0.016 total

$ time python -c 'print "Hello world!"'
Hello world!
python -c 'print "Hello world!"'  0.00s user 0.01s system 64% cpu 0.016 total

Note 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.

gorun will correctly recompile the file whenever necessary.

Where are the compiled files kept?

They are kept under $TMPDIR (or tmp), in a directory named after the hostname and user id executing the file.

You 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.

Ubuntu packages

There are Ubuntu packages available that include gorun:

sudo add-apt-repository ppa:niemeyer/ppa 
sudo apt-get update 
sudo apt-get install golang 

How to build and install gorun from source

Just use goinstall:

$ goinstall launchpad.net/gorun

Reporting bugs

Please report bugs at:

License

gorun is licensed under the GPL.

Contact

To get in touch, send a message to gustavo.niemeyer@canonical.com

gorun (last edited 2012-06-10 22:34:14 by 200-203-57-54)