As Go is becoming the language of the "system". I wonder if it's possible to run Go code as a script, without compiling it, is there any possibility to do that?
The motivation (as there were questions as for motivation), taken from How to use Scala as a scripting language
Problem You want to use Scala as a scripting language on Unix systems, replacing other scripts you’ve written in a Unix shell (Bourne Shell, Bash), Perl, PHP, Ruby, etc.
UPDATE:
I wonder how much I can "abuse" go run
to be able to have much Go code running as scripts
though compiled (which I like that its compiled) but it looks like go run
can give me the opportunity to replace scripting
, that is have source files on servers and run them as source while getting compiled by the go run
but I still manage sources and not executables.
UPDATE: in addition saw gorun
gorun - Script-like runner for Go source files.
Though there is a motivation and tools which tried to workaround not being able to run as script, I will not go for it, +I've been told it's not production ready and was advised not to use it in production because it's not production ready, it's out of it's purpose and would need dump the scripting convenience in favour of Go. (I don't have anything against compiling, static typing, I'm a big fan of it, but wanted something similar to scripting convenience).
go run main.go
what you're looking for ? However, the code is still compiled under a temporary folder..go
files with imports and fully blown scripts. this would now enable me i think at least to replace other unix scripts such asUnix shell (Bourne Shell, Bash), Perl, PHP, Ruby
with go scripts, what do you think?so people can look at the source
, as a good developer, and not just a sysadmin with a bunch of scripts within some folder, i suspect you ll version your success with a vcs ? Won t you ? That will be a great way to share and let co workers checkout then study the source. Note that togo run
means that the running system has a version of go installed, which may be heavy for some environments in comparison to the deployment of a compiled binary.