How to add Bash script to cloudbuild deployment, job?

version 1 steps:- name: ‘bash’ args: [‘echo’, ‘I am running a bash command’] version 2 steps: – name: ‘gcr.io/cloud-builders/gcloud’ – entrypoint: ‘bash’ – args: – ‘-eEuo’ – ‘pipefail’ – ‘-c’ – |- if (( $(date ‘+%-e’) % 2 )); then echo “today is an odd day” else echo “today is an odd day, with an even number” fi – name:…

How Golang DB migration tool work?

migrate Database migrations written in Go. Use as CLI or import as library. Migrate reads migrations from sources and applies them in correct order to a database. The migration tool uses a schema_migrations table. One table exists for one DB. mysql> select * from schema_migrations; +———+——-+ | version | dirty | +———+——-+ | 33 | 0 | +———+——-+ 1 row…

Tests Timing Out? Check Go Tests Parallelism

Go Tests Parallelism The command go test ./… lists all packages in the current directory, builds tests executable for each package, and runs them. The run part is interesting. By default, the number of packages executed in parallel is equal to the value of GOMAXPROCS variable. On my laptop, it is 12 which is the number of CPU cores available.…

What is SemVer or Semantic Versioning?

In the Linux world, kernel releases follow MAJOR.MINOR.PATCH version format. Semver is a similar concept. It advises to follow a simple set of rules: Major version is changed for incompatible changes. Minor versions are changed for new functionality Patch version is changed after bug fixes. Versions are always incremented and reset to zero: Patch version is set to zero if…

golang: NewReader vs NewBufferString

NewReader func bytes.NewReader(b []byte) *bytes.Reader bytes.NewReader on pkg.go.dev NewReader returns a new Reader reading from b. NewBufferString func bytes.NewBufferString(s string) *bytes.Buffer bytes.NewBufferString on pkg.go.dev NewBufferString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string. Difference // A Reader implements the io.Reader, io.ReaderAt, io.WriterTo, io.Seeker,…

go: cannot find main module, but found .git config to create a module there, run: go mod

go: cannot find main module, but found .git/config to create a module there, run: go mod This problem occurred in a monorepo opened in VSCode. The repo has many services placed in isolated directories with respective go.mod files. I realized from various sources that the problem is from two places: Move the mono repo under $GOPATH/src. The ~/.zshrc or ~/.bashrc…

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…