Practicing golang
golang
Sunday, December 4, 2016
Sunday, November 6, 2016
golang Hello
Everything in go is a package
I use docker to practice go
package main
import "fmt"
We import the fmt package
go get github.com/golang/example/hello -- > this command will go and get the hello program on github
go get github.com/golang/example/hello/... - > this will get the program and builds all the code under the directory
I use docker to practice go
package main
import "fmt"
We import the fmt package
go get github.com/golang/example/hello -- > this command will go and get the hello program on github
go get github.com/golang/example/hello/... - > this will get the program and builds all the code under the directory
for gover in 1.2 1.3 1.4; do docker run -v $GOPATH:/go golang:$gover sh -c "go get github.com/golang/example/hello/... && hello "; done
docker run -it -v $GOPATH:/go golang:1.2
docker run -it golang:1.2 sh -c "go get github.com/golang/example/hello/... && hello "
for i in 1.2 1.3 1.5 1.4 1.6 ; do docker run -v $GOPATH/src:/go/src golang:$i sh -c "go get github.com/golang/example/hello/... && hello && echo $i"; done
Hello, Go examples!
1.2
Hello, Go examples!
1.3
Hello, Go examples!
1.5
Hello, Go examples!
1.4
Hello, Go examples!
1.6
So , this is the way to run the code in multiple versions of Go
If we mount just the $GOPATH instead of $GOPATH/src , then we run into following error
# github.com/golang/example/hello
src/github.com/golang/example/hello/hello.go:22: import /go/pkg/linux_amd64/github.com/golang/example/stringutil.a: object is [linux amd64 go1.2.2 X:none] expected [linux amd64 go1.5.4 X:none]
# github.com/golang/example/hello
src/github.com/golang/example/hello/hello.go:22: import /go/pkg/linux_amd64/github.com/golang/example/stringutil.a: object is [linux amd64 go1.2.2 X:none] expected
This is because , the code is first compiled in 1.2 and for later versions of go , there is a link , that is created between the compiled version of go and the rest of the versions
=======================================================================
Minimizing the size of the docker images
--------------------------------------------------
Subscribe to:
Comments (Atom)