Approaching go(lang) : my IDE definition
I like the idea is that a project brings the whole development environment, in other words the projects has to be “battery included”.
I have worked with ‘VsCode’ for some time and I appreciate its flexibility but I also like it seems I am working with a slightly friendlier version of Vi or Emacs.
I need to implement a service with a lot of concurrency and parallelisms and since I wanted to do it for a while, I want to implement it in Go. The service will have a Rest interface and therefore I would like to explore the interoperability between Go and OpenApi .
I don’t want to install Go on my macbook, on the contrary, I don’t want to install any tools anymore and treat each development project as a unit in its own right … so I decided to use the development mode inside containers provided by VsCode.
First I had to define a docker that contains all the tools that I love to use and that make my life easier …. I certainly can’t give up my zsh or ‘oh my shell’ here, I took an example from the Microsoft portal dedicated to development in Go
I’ve extended, compiled and uploaded it to the docker hub.
https://hub.docker.com/repository/docker/marcocipri/vscode-remote-dev-go
This image contains the main GoLang tools and is the base for the dev container. I preferred to insert only a few indications in the final Dockerfile which uses the image already loaded on dockerHub whit ‘golang image: 1’ which loads the ‘go1.14.3’.
The development environment in this mode uses the environment of VsCode which lives in a Docker generated following the instructions in the Dockerfile present in the
“.devcontainer”
directory. This Dockerfile imports the ‘oh my shell’ suite, agnoster theme abd git, golang plugins.
# Install gocode-gomod
RUN export CHSH=no \
sh -c “$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" \
sed -i ‘s/robbyrussell/agnoster/g’ /home/vscode/.zshrc \
sed -i ‘s/(git)/(git go golang)/g’ /home/vscode/.zshrc
In the same directory the file
“devcontainer.json”
indicates how the user and the IDE interacts with the newly created docker. Sets the shell
“terminal.integrated.shell.linux”: “/bin/zsh”,
the go tool path
“go.gopath”: “/go”
forwarding the port 9000 for external testing
at the end of the docker building, the project code is pulled in ‘src’ local dir as golang does.
“postCreateCommand”: “go get github.com/marcocipri/go-openapi-go”
Regenerating everything with a more updated version wouldn’t be a big problem.
below how works.