Golang
Benefits of Golang
01/08/18 22:27
Go is an open source programming language that makes it easy to build simple, reliable, efficient software and provides a robust development experience and avoids many issues that existing programming languages have. The strengths of Go are that it
Easy to learn
Go is so small and simple that the entire language and its underlying concepts can be studied in just a couple of days
Built-in concurrency
Go was written in the age of multi-core CPUs and has easy, high-level CSP-style concurrency built into the language compared the other languages Java, JavaScript, Python, Ruby, C, C++ have been designed in the 1980s-2000s when most CPUs had only one compute core.
Uses OO — the good parts
Go takes a fresh approach at object-orientation with those learnings in mind. It keeps the good parts like encapsulation and message passing. Go avoids inheritance because it is now considered harmful and provides first-class support for composition instead.
Modern standard library
Languages including Java, JavaScript, Python, Ruby were designed before the internet was the ubiquitous computing platform it is today. Hence, the standard libraries of these languages provide only relatively generic support for networking that isn’t optimized for the modern internet. Go was created a decade ago when the internet was already in full swing. Go’s standard library allows creating even sophisticated network services without third-party libraries.
Extremely fast compiler
Go is designed from the ground up to make compilation efficient and as a result its compiler is so fast that there are almost no compilation delays. This gives a Go developer instant feedback similar to scripting languages, with the added benefits of static type checking.
Easy cross compilation
Go supports compilation to many platforms like macOS, Linux, Windows, BSD, ARM, and more. Go can compile binaries for all these platforms out of the box. This makes deployment from a single machine easy.
Executes very fast
Go runs close to the speed of C. Unlike JITed languages (Java, JavaScript, Python, etc), Go binaries require no startup or warmup time because they ship as compiled and fully optimized native code
Small memory footprint & deployment size
Runtimes like the JVM, Python, or Node don’t just load your program code when running it. They also load large and highly complex pieces of infrastructure to compile and optimize your program each time you run it. This makes their startup time slower and causes them to use large amounts (hundreds of MB) of RAM. Go processes have less overhead because they are already fully compiled and optimized and just need to run
Easy to learn
Go is so small and simple that the entire language and its underlying concepts can be studied in just a couple of days
Built-in concurrency
Go was written in the age of multi-core CPUs and has easy, high-level CSP-style concurrency built into the language compared the other languages Java, JavaScript, Python, Ruby, C, C++ have been designed in the 1980s-2000s when most CPUs had only one compute core.
Uses OO — the good parts
Go takes a fresh approach at object-orientation with those learnings in mind. It keeps the good parts like encapsulation and message passing. Go avoids inheritance because it is now considered harmful and provides first-class support for composition instead.
Modern standard library
Languages including Java, JavaScript, Python, Ruby were designed before the internet was the ubiquitous computing platform it is today. Hence, the standard libraries of these languages provide only relatively generic support for networking that isn’t optimized for the modern internet. Go was created a decade ago when the internet was already in full swing. Go’s standard library allows creating even sophisticated network services without third-party libraries.
Extremely fast compiler
Go is designed from the ground up to make compilation efficient and as a result its compiler is so fast that there are almost no compilation delays. This gives a Go developer instant feedback similar to scripting languages, with the added benefits of static type checking.
Easy cross compilation
Go supports compilation to many platforms like macOS, Linux, Windows, BSD, ARM, and more. Go can compile binaries for all these platforms out of the box. This makes deployment from a single machine easy.
Executes very fast
Go runs close to the speed of C. Unlike JITed languages (Java, JavaScript, Python, etc), Go binaries require no startup or warmup time because they ship as compiled and fully optimized native code
Small memory footprint & deployment size
Runtimes like the JVM, Python, or Node don’t just load your program code when running it. They also load large and highly complex pieces of infrastructure to compile and optimize your program each time you run it. This makes their startup time slower and causes them to use large amounts (hundreds of MB) of RAM. Go processes have less overhead because they are already fully compiled and optimized and just need to run
Dependency management in Golang
15/04/18 18:14
Glide was one of the top tool for dependency management for Go. The Glide may become obsolete because of Dev packages introduced in Golang.
dep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. dep is safe for production use. Initially there was planning to integrate deployment into go 1.10.x version but still it has long way. So now you have to install and use separately.
Following are the examples for dep command.
dep init set up a new project
dep ensure install the project's dependencies
dep ensure -update update the locked versions of all dependencies
dep ensure -add github.com/pkg/errors add a dependency to the project
- Message from Glide team :
dep is a prototype dependency management tool for Go. It requires Go 1.9 or newer to compile. dep is safe for production use. Initially there was planning to integrate deployment into go 1.10.x version but still it has long way. So now you have to install and use separately.
Install dep package
- $ brew install dep
- $ brew upgrade dep
Create the project inside $GOPATH
- Create new project under $GOPATH/src/elasticcloudapps.com/hellodep
- package main
- import (
- )
- func main() {
- }
- Initialize dep
- Dep needs two files called Gopkg.lock and Gopkg.toml. You can initialize these files with following
- $ dep init
- Locking in master (d644981) for transitive dep golang.org/x/crypto
- Locking in master (2281fa9) for transitive dep golang.org/x/sys
- Using ^1.0.5 as constraint for direct dep github.com/sirupsen/logrus
- Locking in v1.0.5 (c155da1) for direct dep github.com/sirupsen/logrus
- After this the new files will be generated.
Following are the examples for dep command.
dep init set up a new project
dep ensure install the project's dependencies
dep ensure -update update the locked versions of all dependencies
dep ensure -add github.com/pkg/errors add a dependency to the project
Setting up Go development environment
02/03/17 21:39
Go is fast growing programming language, so I thought it would be helpful to show how to setup and run Go programs on your machine. The instruction is for Mac OS X. Homebrew is required. If you don't have home-brew in your local environment, follow this link to setup home brew in your Mac development environment.
https://brew.sh/
$ brew install go
In order to run Go within your terminal, you’ll need to setup the GOPATH environment variable. This will allow Go to properly locate your workspace in order to run your code and manage your packages. I have my workspace "code" inside my home directory. ($HOME/code") and or Golang I have in $HOME/code/go. I'm using bash profile to setup GOPATH.
1. Edit ~/.bash_profile.
2. Add following lines to bash_profile
export GOPATH="$HOME/code/go"
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
3. I.e. source .bash_profile file or close and open terminal.
$ source ~/.bash_profile
After the setup when you type go you should see as below.

https://brew.sh/
$ brew install go
In order to run Go within your terminal, you’ll need to setup the GOPATH environment variable. This will allow Go to properly locate your workspace in order to run your code and manage your packages. I have my workspace "code" inside my home directory. ($HOME/code") and or Golang I have in $HOME/code/go. I'm using bash profile to setup GOPATH.
1. Edit ~/.bash_profile.
2. Add following lines to bash_profile
export GOPATH="$HOME/code/go"
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
3. I.e. source .bash_profile file or close and open terminal.
$ source ~/.bash_profile
After the setup when you type go you should see as below.
