Skip to content

madrisan/go-without-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go without (installing) go

This small Docker project was started to run go without installing go.

Why not installing a go compiler and toolchain provided by your Linux distribution?

These are some possible reasons:

  • the compiler shipped by the distribution may not be the latest (or a recent) stable version released upstream;
  • we may want to download and build a project and all its dependencies on a clean system all the time;
  • we may want to cross compile a Go project;
  • we may want to test different versions of the Go compiler.

Pre-requirements

Docker-CE must be installed and the docker daemon running.

Running a program in a container

make go run /source/helloworld.go

or (because /source is the workdir of the Docker container)

make go run helloworld.go

You can replace make by make QUIET=1 to reduce the verbosity of the output messages.

Compiling a program in a container

make go build helloworld.go
./source/helloworld

make go "get -v github.com/golang/example/hello/..."
./bin/hello

Cross compilation

make go GOENV="-e GOOS=darwin -e GOARCH=amd64" build helloworld.go
  >> ./source/helloworld
make go GOENV="-e GOOS=darwin -e GOARCH=amd64" "get -v github.com/golang/example/hello/..."
  >> bin/darwin_amd64/hello
file bin/darwin_amd64/hello
  >> bin/darwin_amd64/hello: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS>

Help message

make help

If you prefer, you can define the following two command aliases (in the file ~/.bashrc for instance)

alias dgo="sudo docker run -v $PWD/source:/source -v $PWD/bin:/go/bin --rm gowithoutgo_alpine"
alias dgofmt="sudo docker run -v $PWD/source:/source -v $PWD/bin:/go/bin --rm --entrypoint gofmt gowithoutgo_alpine"

and run and compile your Go project this way:

make image
. ~/.bashrc

dgo run helloworld.go

dgo build helloworld.go
./souces/helloworld

or format the source code with the tool gofmt:

dgofmt -w helloworld.go

Go language resources

Some resources for learning the Go language:

Releases

No releases published

Packages

No packages published