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