Thursday, December 5, 2013

go get pkg ~ easy made easier for project dependency management

For past sometime I've been trying out ways to improve practices upon awesome capabilities from GoLang. One of the things have been having a 'bundle install' (for ruby folks) or 'pip require -e' (for python folks)  style capability... something that just refers to an text file part of source code and plainly fetches all the dependencies path mentioned in there (for all others).

It and some other bits can be referred here...
https://github.com/abhishekkr/tux-svc-mux/blob/master/shell_profile/a.golang.sh#L31

It's a shell (bash) function that can be added to your Shell/System Profile files and used...

go_get_pkg(){   if [ $# -eq 0 ]; then if [ -f "$PWD/go-get-pkg.txt" ]; then PKG_LISTS="$PWD/go-get-pkg.txt"     else touch "$PWD/go-get-pkg.txt"       echo "Created GoLang Package empty list $PWD/go-get-pkg.txt"       echo "Start adding package paths as separate lines." && return 0     fi else PKG_LISTS=($@)   fi for pkg_list in $PKG_LISTS; do cat $pkg_list | while read pkg_path; do echo "fetching golag package: go get ${pkg_path}";         echo $pkg_path | xargs go get     done done }
---
What it do?
If ran without any parameters. It checks for current working directory for a file called 'go-get-pkg.txt'. If not found creates one empty file by that name. To be done at initialization of project. If found, then it iterates through each line and pass it directly to "get get ${line}". If ran with parameters. Each parameter is treated as path to files similar to 'go-get-pkg.txt' and similar action as explained previously is performed on each file.
Sample 'go-get-pkg.txt' file
-tags zmq_3_x github.com/alecthomas/gozmq github.com/abhishekkr/levigoNS github.com/abhishekkr/goshare
---