Go - constant variables and const keyword

Brief Programming languages have the notion of constants which means “variables that can not be mutated once declared and initialized”. Go also has almost the same meaning, but in a different context. To initialize a variable as a constant with a value of 10, we can do something like this: 1 const DISCOUNT = 10 In Go, constants mean “storing a literal to a variable”, this can be seen as a version of pattern matching in Erlang. ...

May 12, 2024 · 2 min · Aleem Isiaka

Running Go programs with a specific version

This post shares how you can run an old version of Go while still having your machine’s default Go - which is newer.

May 10, 2024 · 2 min · Aleem Isiaka

Autocompile Go

First, install CompileDaemon: 1 $ go get github.com/githubnemo/CompileDaemon && go install github.com/githubnemo/CompileDaemon Then, from the root of the project, create a Make file: 1 $ touch Makefile And add the below content: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 GOCMD ?= go GOBUILD = $(GOCMD) build GOCLEAN = $(GOCMD) clean GOTEST = $(GOCMD) test GOGET = $(GOCMD) get BINARY_NAME = project_name BINARY_UNIX = $(BINARY_NAME)_unix default: all all: test build build: $(GOBUILD) -o ../$(BINARY_NAME) -v -ldflags="-X main.VERSION=$(TAG)" test: $(GOTEST) -v ./... clean: $(GOCLEAN) rm -f $(BINARY_NAME) rm -f $(BINARY_UNIX) run: build ./$(BINARY_NAME) dev: CompileDaemon -build="$(GOBUILD) -o ../$(BINARY_NAME)" -command="../$(BINARY_NAME)" -color="true" -exclude-dir=.git -exclude=".#*" Finally, from the root of your project: ...

August 21, 2021 · 1 min · Aleem Isiaka