How to Add Multiple Directories in GOPATH with VSCode?

Since go versions keep moving up, maintaining GOPATH inside a Go installation path is a pain. export GOPATH=/home/a-user/go/1.14.9 ls /home/a-user/go/1.14.0/src bitbucket.org github.com go.uber.org golang.org gopkg.in Adding multiple directories in GOPATH Create a directory e.g. for work mkdir $HOME/mywork GOPATH assumes a structure in the directory, so create three directories inside. ls $HOME/mywork bin pkg src You will do all your…

VSCode Plugins for Golang Development

Rich Go language support for Visual Studio Code Theme: Dark Knight: A simple dark theme for Golang projects Git Blame & Git History Postfix templates for Golang Adds go to implementation on context menu All-language autocompleter — TabNine uses machine learning to help you write code faster. This is a minimal list of Go development extensions in my opinion.

What is Auth and Capture?

An auth and capture transaction is suitable for credit-based purchases with a delay involved. An example is an e-commerce sale that involves shipping after a few days. The payment is authed at the time of purchase and captured at the time of shipping. Authorize: authorize a subscriber’s credit card/ account for a period (expires after 30 days) check with the…

Strategy Pattern in Golang

Introduction The strategy is a behavior pattern. It fits where multiple choices for an interface are available and the design would allow switching them dynamically. Conditions A set of choices with similarity in the interface Dynamic update of a choice Example A cache with evictions Multiple eviction algorithms Cache could switch to a different algorithm dynamically A duck type has…

golang: How to Add Better Context to Errors

golang: How to Add Better Context to Errors There are at least three ways to add more context to errors. fmt.Errorf errors package zap library package main import ( “errors” “fmt” werr “github.com/pkg/errors” “go.uber.org/zap” ) // 1. wraps with a message func wrap(e error) error { return fmt.Errorf(“another layer – %w”, e) } // 2. wraps with callstack and message…

Get a Free Public Web Address

Get a Free Public Web Address What is ngrok? Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. Run personal cloud services from your home Demo websites without deploying Build webhook consumers on your dev machine Test mobile apps connected to your locally running backend Stable addresses for your connected devices that are deployed…

How to Check nil Interface in Golang?

It’s not a good idea to check an interface for nil. Try the following code: type user interface{} type staff struct{} func compareNil() { var generic user generic = nil // works as expected fmt.Printf(“value=%v type=%T (generic==nil)=%v\n”, generic, generic, generic == nil) generic = (*staff)(nil) // fails my expectation fmt.Printf(“value=%v type=%T (generic==nil)=%v\n”, generic, generic, generic == nil) } go playground:…

Google Auth App Not Working: Quits on Launch on iOS

Google Auth App Not Working: Quits on Launch on iOS After upgrading iOS, the Auth app started exiting on launch. Solution Go to Settings->General->Storage Now find Google Auth App in the list Offload App. It retains all your data. Install again. It could work now!