gorun可以使GO语言代码代码作为shebang#!脚本使用,如:
#!/usr/bin/gorun package main func main() { println("Hello world!") }
然后:
$ chmod +x hello.go $ ./hello.go Hello world!
安装gorun
go get github.com/erning/gorun cp $GOPATH/bin/gorun /usr/bin
在使用gorun时需要在包含main()的.go代码开始处增加#!/usr/bin/gorun,然后设置文件为可执行即可使用gorun来运行了。这些文件只能用gorun来编译,因为#!在go中是非法的。
性能测试
$ 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
参考:
[1] https://github.com/erning/gorun
转载请注明:爱开源 » Go语言版shebang脚本gorun