I’ve just started playing with Go and I have a few questions which are mostly to get a good structure to start with so I’m going forward with good practices for the language. I have read both the official documentation, not in full - I’m trying to take things in small chunks, and some people suggesting best practices based on experience through searches.
Q1: The first documentation I came across talking about splitting externals from your own code by setting GOPATH to something like: $HOME/Go/external:$HOME/Go/internal and by doing so all code will automatically download into $HOME/Go/external since it’s the first on the path.
However, now I am seeing that as of version 1.5 (I am using 1.7) you can just put a vendor folder in you project path and Go will put all externals in the vendor directory.
Does this make the use of $HOME/Go/external obsolete or am I confusing two separate issues with each other? I’m from the Drupal community and the vendor folder is anything pulled from projects external to Drupal’s own code base.
Q2: If you look at my basic structure below you can see that my projects are diycs/sc & diycs/scsims. Does this mean I should put a vendor folder at diycs/sc/vendor and diycs/scsims/vendor? Or, should there be a vendor folder for each package that has vendor dependencies such as “diycs/sc/server/vendor”?
Q3: Part of the reason for Q2 is I am a little uncertain about exactly what is a project folder. My understanding is that anything at the level of src/author/project is a project. Is this correct?
Q4: I am using the liteide for Go development. Whenever I create a package it creates two files as you can see from the tree below one file is always doc.go. Is this something that I am required to manually fill out… I’m just trying to ascertain why it’s put there automatically. If so, usually we document what’s in a source code file from within the file so what does this file add?
My current structure that I am asking about:
Go ├── external │ └── src └── internal └── src └── diycs ├── sc │ ├── cmd │ │ └── runsims │ │ ├── doc.go │ │ ├── main.go │ │ └── runsims │ ├── pkg │ │ └── server │ │ ├── doc.go │ │ ├── http.go │ │ └── server.go │ └── vendor └── scsims ├── cmd │ └── runsims │ ├── doc.go │ └── main.go ├── pkg │ └── sims │ ├── doc.go │ └── sims.go └── vendor
Finally, I would like to offer an improvement (for Linux users) to the recommendations on how to setup GOPATH and PATH in a few shell lines which is below. Admittedly, I’m just gettting started it may be flawed because of things I don’t know yet:
# In ~/.profile
#
# These are for "Go"
#
# Adjust absolute path suit your needs
GoPP=$HOME/Jobs/Go # PP = PathPrefix.
# Adjust subpaths and alternate paths to suit your needs.
# My installation automatically added /usr/share/go/contrib, not
# sure it's use yet but others will probably not want it.
export GOPATH=$GoPP/external:$GoPP/internal:/usr/share/go/contrib
# This sets path for bin file taking into account having multiple
# paths in GOPATH
export PATH=$PATH:$(echo $GOPATH|sed 's#:#/bin:#g')/bin
# Some features (at least through liteide) don't like src missing
# so make sure they all exist.
srcPath=$(echo $GOPATH|sed 's#:#/src #g')/src
mkdir -p $srcPath