Home - mirkar/mygolang GitHub Wiki
Creating from scratch
go get github.com/golang/example/hello
Installing GO
First let's set GO development environment, and as an example I'm going to use zlp00150 server. Use Linux distribution go1.9.4.linux-amd64.tar.gz. Installaton directory /opt/app/workload/local/go1.9.4
. Add to .profile the lines below:
export GOROOT=/opt/app/workload/local/go1.9.4
export PATH=$PATH:$GOROOT/bin
Leaving the things as is, will make GOPATH pointed to its default location that is go directory inside the user's home
[m93658@zlp00150 dm0434]$ go env GOPATH
/home/m93658/go
However I want all my golang projects to be located inside /opt/app/workload/staff/dm0434/projects/go, also I want any of my compiled programs could be easily launched by simply typing their names rather than via full paths. To do this I created a file golang to be sourced by shell:
export GOPATH=/opt/app/workload/staff/dm0434/projects/go
export PATH=$PATH:$(go env GOPATH)/bin
So executing . /opt/app/workload/staff/dm0434/goland
provides me with an exact environment I want.
My plan is to keep my projects on github, and the initial project I want to play with has a name mygolang, which is based on the sample from https://golang.org/doc/code.html
To do this first I create github.com/mirkar/mygolang/hello inside my current GOPATH, create hello.go there and than run git init
inside github.com/mirkar/mygolang.
Now create an empty mygolang repository on github and push the code there.
Getting from GitHub
After the repository is set, you can run go get github.com/mirkar/mygolang/hello
on any server (with GO installed of course) ans as result the repository will be downloaded from github and the code automatically compiled:
[m93658@zlp00149 ~]$ go get github.com/mirkar/mygolang/hello
[m93658@zlp00149 ~]$ cd $GOPATH
[m93658@zlp00149 go]$ ls
bin pkg src
[m93658@zlp00149 go]$ ls bin
hello
[m93658@zlp00149 go]$ hello
Hello, Go!
dlrow ,olleh
hello, world
[m93658@zlp00149 go]$ ls -a src/github.com/mirkar/mygolang/
. .. .git hello README.md stringutil
The same approach works for the original sample itself
[m93658@zlp00149 go]$ go get github.com/golang/example/hello
[m93658@zlp00149 go]$ hello
Hello, Go examples!
[m93658@zlp00149 go]$ ls -a src/github.com/golang/example/
. .. appengine-hello .git gotypes hello LICENSE outyet README.md stringutil template