Golang-Go Over-view

Hi Everyone,

Not sure if this will help anyone but here I “go”, no pun intended.

Go is a painful program to; not only install, set paths, but to just run a simple “hello, fricken world”.

Installation file can be found here;
Downloads - The Go Programming Language # watch out for dependencies. Fun stuff

Help
Home · golang/go Wiki · GitHub # hmmm, definitely not Zed Shaw standard of teaching
https://forum.golangbridge.org/ # very helpful if not confusing at first

Advantages; It’s tree structure is great for full stack developers. Problem is, I’d hardly say I fall into that category.

Go tree structure looks like this;

    hello                          # command executable
    outyet                         # command executable
pkg/
    linux_amd64/
        github.com/golang/example/
            stringutil.a           # package object
src/
    github.com/golang/example/
        .git/                      # Git repository metadata
	hello/
	    hello.go               # command source
	outyet/
	    main.go                # command source
	    main_test.go           # test source
	stringutil/
	    reverse.go             # package source
	    reverse_test.go        # test source
    golang.org/x/image/
        .git/                      # Git repository metadata
	bmp/
	    reader.go              # package source
	    writer.go              # package source
    ... (many more repositories and packages omitted) ...

Out of all of those, the only ones I have used are;

src/
      github.com/
            .git/
            hello/
                   hello.go // prints out in terminal 
                               hello go :space_invader:
            stringutil/ 
                  reverse.go // prints out in terminal
                                the reverse of "\n!oG, olleh"

Negatives; Can be used from Atom using gksu from terminal (DOES NOT ALWAYS WORK). Then have to close Atom to input the commands in terminal.

NOTE works better with nano, vim, or emac2. ALSO Go environment paths are deleted when terminal closes and there does not seem to be a work around for this as per forum. Therefore each time you close you will have to reset paths via;

$ source ~/.bash_profile // see below.

Setting Go environments for the first time Linux bash shell:

sudo nano ~/.bash_profile

add line 

export GOPATH=$HOME // was meant to be HOME/go, 
                       I somehow ended up with HOME and just
                       thanked the programming gods it worked.
                       whatever you do, do not add / 
                       to the end of HOME
and

$ export GOBIN=$HOME/bin // so 'go install' has a rubbish 
                            bin to dump files after install

save and exit nano, then run from terminal;

$ source ~/.bash_profile // basically you run this for every 
                            terminal you open, but wait there is more

To view paths have worked, run from terminal;

$ go env
 

Screenshot from 2017-10-31 22-45-47

Thankfully the next time you open terminal, you only have to do.

$ source ~/.bash_profile 

cheers tc

ps, Sorry for the rant

1 Like