I’m reading Learning Go by Jon Bodner. The opening chapters have some nice tips on getting a good developer environment. Vim has the excellent vim-go plugin that bundles a ton of nice stuff. Here are some notes I took while I got things setup.
My .vimrc is here.
My detailed notes from reading the book are here, and what follows below is just the subset that deals with dev environment.
Install vim-go: it comes with a massive set of tools.
goimports for some neat stuff that gofmt doesn’t do. Install with:
go install golang.org/x/tools/cmd/goimports@latest
And run with:
goimports -l -w .
Vi: Just save it.
Linting with golint
go install golang.org/x/lint/golint@latest
SA with govet
go vet ./...
This does not catch subtle bugs around shadow variables. So consider installing
shadow as well:
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
Combine golint, govet with golangci-lint
This tool runs 10 different linters by default and support dozens others.
Install: see official docs
- Code completion is with
:Tagbar is bound to
:GoDef is bound to
GoDefStack shows you how deep you’ve jumped,
Ctrl-T just pops to the last hop
.DEFAULT_GOAL := build
go fmt ./...
go vet ./...
go build hello.go
strace -f -e trace=network -o /tmp/strace.txt -s 10000 <cmd> <args>
I saw the following neat little trick in this link:
# renaming a long file-name using a regex
$ touch config.txt
$ mv config.txt !#:1:s/txt/json
The exact meaning of the
!# is, quoting from the man page:
Event Designators An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list.
! Start a history substitution, except when followed by a blank, newline, carriage return, = or ( (when the extglob shell option is enabled using the shopt builtin).
!# The entire command line typed so far.From ‘man bash’
i.e. most people know that bash can insert things from history using commands like
!50 (i.e. rerun last command and rerun the 50th history item respectively).
!# let’s you take something from the existing line and re-use it.
Here is another example, from here:
curl http://beyondgrep.com/ack-2.14-single-file > ~/bin/ack && chmod 0755 !#:3
In this case,
!#:3 takes the 3rd element from the existing command. Starting from zero, that turns out to be
~/bin/ack in this case.
docker-compose up --abort-on-container-exit
This will stop all containers launched via
docker-compose when one of the containers stops.
Update: Looks like subtrees are a nicer alternative to submodules. Anyway..
- To update all submodules:
git submodule update --init --recursive
- To fetch the latest code from a submodule:
git commit -am "bumping up submodule version"
Then merge the code. The next time the parent repository is pulled,
updating the submodule will get the latest commit in it.