How to install GVM and latest Go (One-Liner)?

The gvm a.k.a. Go Version Manager is an excellent tool to maintain multiple version of Go in your system.

Instruction

If you are using zsh

Assuming that latest go at the moment is 1.14.4 and you are using zsh

zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) \
      && echo "source /home/$USERNAME/.gvm/scripts/gvm" >> ~/.zshrc && source ~/.zshrc \
      && gvm install go1.4 -B && gvm use go1.4 --default \
      && gvm install go1.14.4 && gvm use go 1.14.4 --default

If you are using bash

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) \
      && echo "source /home/$USERNAME/.gvm/scripts/gvm" >> ~/.bashrc && source ~/.bashrc \
      && gvm install go1.4 -B && gvm use go1.4 --default \
      && gvm install go1.14.4 && gvm use go 1.14.4 --default

The above one liner works with Ubuntu as well as Debian.

Explanation

First line (below) will install gvm.

zsh < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

Second line will ensure loading of gvm in your shell and it will load shell configuration again for this instance

echo "source /home/$USERNAME/.gvm/scripts/gvm" >> ~/.bashrc && source ~/.bashrc

Third line will install the go version without source (-B is for Binary) which will be loaded then as default

gvm install go1.4 -B && gvm use go1.4 --default

Fourth line will install the go specified version with source and compile it using go1.4

gvm install go1.14.4 && gvm use go 1.14.4 --default

Worth Sharing?

Go Performance – A Checklist

Avoid Global Mutex

Don’t use a global mutex, keep it tied to structures. Go doesn’t have GIL and it is tempting to create a global mutex to simulate a similar behavior but then why use Go in the first place? You can tie a mutex to a structure to keep its impact as low as possible.

Avoid Defer Functions

Deffer functions are significantly expensive than the non-deferred ones. In the case of static functions, an improved version is compiled but it is still slower than direct functions.

Avoid recreate, reuse Variables

It is a usual way to create a variable in a loop. It takes an extra CPU cycle as well as it would keep Garbage Collection busy. Instead, use sync.Pool

Worth Sharing?

F`k it – Fix it – Psychology

I have just created a page Hire Me and told few friends and one asked me to come over and discuss a few projects his team is working where I can assist. Every single one of them was in Dot Net except one in Go. He is helping a renowned trader who has chosen to stay anonymous. A project is having code name OTAMIA.

Too Hot to Touch!

He stated that because of some inconsistency in an official Client of Kite Connect, the project is becoming annoying and unnecessary harder. His approach was not to touch the official API but use some duplicate structures to fix the issue or some conversions. He didn’t touch the official code but then again it wasn’t new. I created a framework on which every single Shopify App was build in SpiceGems and there, everyone worked on the framework decided not to touch what I wrote and this made a huge pain for everyone. I asked them why – they just said it is official (part of a framework)! My response was ‘F`k it Fix it’

F`k it – Fix it

The whole job of mine is to save time and pain. So we fixed the following issues or added feature (so far)

  1. Turned two packages into single – R.I.P compatibility.
  2. This enabled us to use a single structure for both packages.
  3. The error was coming as nil even when there was one – we fixed it.
  4. Data in converting JSON to STRUCT was giving blank (0000-00-000) dates – we added another known date format.
  5. We added a new flag to enable OI to be fetched.

All of the above changes were made within 2 hours but this removed all the unnecessary conversion, custom structure for proper JSON conversion and managing time column in our project. All of this so far had taken more than a week.

Be Brutal – Consultant’s Principal

Coding must be enjoyable and just because something is coming under the tag “Official” it doesn’t mean that there is no scope of improvement or you got to use that in the same way. If I can tell my team to f’k my framework, I can tell to f’k anyone’s. Knowledge and Tech both are evolving and we are all learning. Wherever you can save time and pain – just go ahead. Although, sometimes initial pain would save a lot of pain and time in the future. You will have to make a wise choice.

Open-Source KiteAPI

It was almost impossible for my client to let us make it opensource but he agreed and we have a code over here under MIT license.

https://github.com/VarunBatraIT/kiteapi

Worth Sharing?