<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>go-tools on Golang</title><link>https://golang.k5kc.com/categories/go-tools/</link><description>Recent content in go-tools on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:19:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/categories/go-tools/index.xml" rel="self" type="application/rss+xml"/><item><title>My VS Code Congig for Go</title><link>https://golang.k5kc.com/2020/08/16/10.vs-code-settings-for-go/</link><pubDate>Sun, 16 Aug 2020 00:19:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/10.vs-code-settings-for-go/</guid><description>{ &amp;#34;go.lintTool&amp;#34;: &amp;#34;golangci-lint&amp;#34;, &amp;#34;go.formatTool&amp;#34;: &amp;#34;goimports&amp;#34;, &amp;#34;go.useLanguageServer&amp;#34;: true, &amp;#34;go.lintOnSave&amp;#34;: &amp;#34;package&amp;#34;, &amp;#34;go.vetOnSave&amp;#34;: &amp;#34;package&amp;#34;, &amp;#34;go.vetFlags&amp;#34;: [ &amp;#34;-all&amp;#34;, &amp;#34;-shadow&amp;#34; ] }</description></item><item><title>Understanding the GOPATH environment variable</title><link>https://golang.k5kc.com/2020/08/16/3.understand-gopath/</link><pubDate>Sun, 16 Aug 2020 00:12:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/3.understand-gopath/</guid><description>The GOPATH environment variable lists places to look for Go code. It defines your workspace. It is likely the only environment variable you&amp;rsquo;ll need to set when developing Go code.
Official documentation:
How to Write Go Code: The GOPATH environment variable Command go: GOPATH environment variable Normally the GOPATH is set in your shell profile (one of ~/.bashrc, ~/.bash_profile, etc).
When you install packages and build binaries, the Go tool will look for source code in $GOPATH/src/ followed by a package import path in order to resolve dependencies.</description></item><item><title>Go Configuration - Environment variables</title><link>https://golang.k5kc.com/2020/08/16/2.go-environment-variables/</link><pubDate>Sun, 16 Aug 2020 00:11:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/2.go-environment-variables/</guid><description>Open up .profile or .zshrc or .bashrc depending on our OS and add/edit following:
#!/bin/bash # Specifies where the Go destribution is installed on the system. export GOROOT=/usr/local/go # Specifies top-level directory containing source code for all our Go projects. # Inside this directory, we need to create 3 more directories viz. &amp;#34;src&amp;#34;, &amp;#34;pkg&amp;#34; and &amp;#34;bin&amp;#34;. export GOPATH=~/adiwork/go # This directory is also known as Go Workspace. # &amp;#34;src&amp;#34; directory inside Workspace represents where all the Go source code will be stored.</description></item><item><title>"go build" and "go install"</title><link>https://golang.k5kc.com/2020/08/16/go-build-vs-go-install/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/go-build-vs-go-install/</guid><description>Let&amp;rsquo;s tidy up the $GOPATH directory and only keep Go source code files left over:
# tree . ├── bin ├── pkg └── src ├── greet │ └── greet.go └── hello └── hello.go 5 directories, 2 files The greet.go is greet package which just provides one function:
# cat src/greet/greet.go package greet import &amp;#34;fmt&amp;#34; func Greet() { fmt.Println(&amp;#34;नमस्ते किंशुक!&amp;#34;) } While hello.go is a main package which takes advantage of greet and can be built into an executable binary:</description></item><item><title>"go get" command</title><link>https://golang.k5kc.com/2020/08/16/5.go-get-command/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/5.go-get-command/</guid><description>&amp;ldquo;go get&amp;rdquo; command is the standard way of downloading and installing packages and related dependencies.
The snippet above basically tells the compiler to import the crypto package available at the github.com/mattetti/goRailsYourself/crypto path. It doesn’t mean that the compiler will automatically pull down the repository, so where does it find the code?
You need to pull down the code yourself. The easiest way is to use the go get command provided by Go.</description></item><item><title>Common Abbreviations Used In Go</title><link>https://golang.k5kc.com/2020/08/16/common-abbreviation/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/common-abbreviation/</guid><description>Following are some of the common Abbreviations used in Go standard libraries:
var s string // string var i int // index var num int // number var msg string // message var v string // value var val string // value var fv string // flag value var err error // error value var args []string // arguments var seen bool // has seen? var parsed bool // parsing ok?</description></item><item><title>Constants in Go</title><link>https://golang.k5kc.com/2020/08/16/2.constants/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/2.constants/</guid><description>Intro Constants are declared like variables, but with the const keyword. Constants can only be character, string, boolean, or numeric values and cannot be declared using the := syntax. An untyped constant takes the type needed by its context.
Example:
const Pi = 3.14 const ( StatusOK = 200 StatusCreated = 201 StatusAccepted = 202 StatusNonAuthoritativeInfo = 203 StatusNoContent = 204 StatusResetContent = 205 StatusPartialContent = 206 ) Constants belong to compile time.</description></item><item><title>Dependency Management - vendoring</title><link>https://golang.k5kc.com/2020/08/16/12.dependency-management-vendoring/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/12.dependency-management-vendoring/</guid><description>Google is well known to have an immense mono repo so go get works well for them. This is not the case with everyone else. By default go get pulls the master branch of the repo you point it at. When you do a go get it pulls in the required dependencies, this means there are issues with reproducibility. As of go 1.5 they looked to address some of the issues by introducing the vendor directory.</description></item><item><title>Install Golang</title><link>https://golang.k5kc.com/2020/08/16/1.install-golang/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/1.install-golang/</guid><description>Installing using OS package manager You might use your package manager to install Go or install manually from the official release binaries. Either way should be easy.
Because the go tool is able to download code from remote repositories, it is often useful to have installed clients for the various supported version control systems. At the time of this writing, they are documented as: Bazaar, Git, Mercurial and Subversion.
They are not mandatory requirements, you might go a long way with just having git installed, and installing others later as required.</description></item><item><title>Unused variables</title><link>https://golang.k5kc.com/2020/08/16/9.unused-variables/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/9.unused-variables/</guid><description>Unused variables in blocked scope are not allowed in Go since they cause maintenance nightmares. If we declare a variable in blocked scope then we must use it or else completely remove it from the block. We cannot have unused variables declared in blocked scope dangling in our source codes. Go throws unused variable errors at compile time only. We should avoid using package level variables. Go doesn&amp;rsquo;t throw unused variable errors at compile time for variables declared at package level.</description></item><item><title>Use govendor to implement vendoring</title><link>https://golang.k5kc.com/2020/08/16/use-govendor-to-implement-vendoring/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/use-govendor-to-implement-vendoring/</guid><description>The meaning of vendoring in Go is squeezing a project&amp;rsquo;s all dependencies into its vendor directory. Since Go 1.6, if there is a vendor directory in current package or its parent&amp;rsquo;s directory, the dependency will be searched in vendor directory first. Govendor is such a tool to help you make use of the vendor feature. In the following example, I will demonstrate how to use govendor step by step:
(1) To be more clear, I clean $GOPATH folder first:</description></item><item><title>Variables</title><link>https://golang.k5kc.com/2020/08/16/1.variables-and-inferred-types/</link><pubDate>Sun, 16 Aug 2020 00:10:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/1.variables-and-inferred-types/</guid><description>In Go, we have to declare a variable before we can use it. This is required and necessary for the compile time safety. Variables are not created at compile time. They are created at run time. The unnamed variables are pointers (like in C). Once we declare a type for a variable, it cannot be changed later. It is static. Declaring with var The var statement declares a list of variables with the type declared last.</description></item></channel></rss>