Categories
GoLang Web Application

Getting started with a Golang web application

Started looking at Golang about a year ago, reading through a few tutorials and writing some script sized programs. At the time I thought I would use Golang for specific sysadmin type tasks. It didn’t really pan out as the time to completion vs bash or python is almost always much lower. Scripting in bash and pythons means you can always fix bugs with just a text editor with no compiling – dependency management is pretty simple, on all linux distros. So I didn’t write anything in Golang for almost a year and forgot most of it! I have an idea for a business tool enabling mapping and execution of organisational objectives, strategy and operations.

Learning with a Project

The only way to learn a programming language is to use it on a project (or many). So I am building a web application that requires:

  • Authentication/Identification/Roles
  • Forms for input
  • Navigation/Searching/SIngle page
  • Charting/Models
  • Persistent data
  • Security controls such as csrf tokens

IDE

Previously I added a bunch of plugins to vim and managed a custom and complex vimrc file. I found that having to manage all of that on numerous workstations was too time expensive. So – in an effort for workstation portability and ease of management, I am trying the GoLand ide by JetBrains. I will decide after my 30 day trial whether or not to pay the 200 usd per year price tag. If it means I write code more often (not avoiding the environment setup, maintenance and portability issues) it may well be worth it. Ended up going with Microsoft Visual Code which is on linux, macos and windows, is opensource, free and quick and easy to set up.

After thinking about what I just wrote above – it is nonsense. I should just take 30 minutes to write down how to set up a decent Golang environment. Started but abandoned: https://mwclearning.com/?p=1858

Tutorial

https://golang.org/doc/articles/wiki/ is a nice short tutorial from the makers or Golang that introduces the basic concepts. That along with A tour of Go are enough to get started.

TechStack

Starting with:

  • Relational database backend (postgres)
  • Javascript frontend (vuejs)
  • Application code (Golang)
  • Framework (gin / echo)
  • Requirement tracking / Agile board (taskworld)
  • Source code management (gitlab.com – free private repos)
  • Integrate Development Environment (Microsoft Visual Code)

Getting started

Tutorials based on what I features are needed to meet requirements.

Categories
GoLang Web Application Random

Free Golang IDE (s) on macos (Visual Studio Code / vim)

Visual Studio Code

Visual Studio Code is a now is Microsoft’s now OpenSource IDE that runs on windows, macos and linux!

Simple set up guide here: https://rominirani.com/setup-go-development-environment-with-visual-studio-code-7ea5d643a51a. Assuming go is installed and ready to do – the download, install and setup took about 5 minutes. Everything just works out of the box and its much less dependency on complex config files and plugins (vs vim).


Vim (abandoned this for Microsoft Visual Code)

Install these if they are not already:

brew install vim
# Note that is is executing arbitrary code from an the vim-go repo 
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 
git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go
  • Customise ~/.vimrc to enable and configure your plugins and shortcut keys
  • Once th ~/.vimrc is added run :GoInstallBinaries to get vim-go’s dependencies

Shortcut keys in this vimrc:

  • \ + b -> build
    • if errors occur toggle forward and back through them with ctrl + n and ctrl + m
    • close quick fix dialogue boxes with \ + a
  • \ + i -> install
  • dif (whilst on func def, delete all contents for func)

Autocompletion sucks though 🙁 so adding neocomplete is a must).

With existing versions of brew installed vim and the introduced dependency of xcode makes the setup time high. I went through this in the past and after a fairly long hiatus from writing code if find nothing is working quite right.