As developer we constantly use tools that let us go faster in our daily tasks, not only go faster also we have to write code with a good quality, because we need to write thinking in the next developer that will have to touch the code, so always choose explicit instead implicit, keep the things simple and Try to not repeat yourself (DRY). In this long way we always continue learning and improving our way of writing code in Go language, some of this tools I listed here:
go get / go install (Go tools)
This cli command lets you get a dependency and install it in your GO_PATH. In the last version of go (1.17.0), “go get/install” was redesigned with modules, and improved usability of it, which will help speed up the process of getting users up to speed.[2]
With go get your will update your dependency and edit go.mod and go.sum. In the best practice of golang they advise to generally not try to consume or edit go.mod and go.sum directly because this should be timeless for the foreseeable future, also it's hard for a human to fully understand the dependency graph by reading a go.mod file. Also with go get you could remove dependencies, the command looks like “go get example.com/theirmodule@none”[2]
Using go tools to get your dependencies your requirements remain consistent and the content of your go.mod file is valid. If you need to search for packages you might find useful, you should query here: https://pkg.go.dev/
“Go mod init “ lets you initialize a new module, and when you are using conventions this ensures it’s available to others via Go tools. Each directory is considered its own package, and each file has its own package declaration line. One repository could have one module or multiple modules (decentralized publishing), the best practice is to have one module by repository because it’s better for upgrade, and maintenance is simpler.[1]
A module could have many packages inside. When Go sees that a package is named main it knows the package should be considered a binary, and should be compiled into an executable file, instead of a library designed to be used in another program. When Go sees a function named main inside a package named main, it knows the main function is the first function it should run. This is known as a program’s entry point. GOPATH is an environment variable where you define where the go binary is. Don't worry if you are not familiar with the GOPATH, because using modules replaces its usage.[3]
“go list -m all” list all dependencies(-m = modules ) with -u list the modules that need an upgrade and “go list -m -versions github.com/lib/pq” list all versions for the lib/pq module. “go mod tidy”: is used for removing unnecessary or unused dependencies.“go install”, let you install the application locally.
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Created profile for existing install of Go at /usr/local/go
Installed GVM v1.0.22
Please restart your terminal session or to get started right away run
`source /home/jennifer/.gvm/scripts/gvm`
Ayu is an extension for visual studio code IDE, this extension implements three themes: Ayu Dark, Ayu Light and Ayu Mirage, this themes lets you highlight the go syntax, as I spent long hours with IDE on my screen it’s comfortable to my eyes to have set Ayu Mirage as theme.