Get GOing with Golang
What is Golang ?
So Golang is a hot language these days. So what actually is Golang. Golang or Go is an open-source programming language developed by Google. The main highlights of golang is its simplicity , high efficiency and mainly strong concurrency support. It is was mainly build to use in building scalable high performing applications, mainly in cloud computing , networking and Distributed systems.
Why Learn GO?
Golang is a language that is gaining popularity really quickly and most organisations have been grabbing a piece of the golang pie. It is more and more used in making scalable applications and since it is a modern language it is more easier to work with.
More opportunities will pop up in the near future in golang. Many main players in the cloud domain is written in golang Kubernetes and Docker are some examples. If you are interested in cloud this would be a nice language in your arsenal. I have been building backend API's in Node and switching to Go was great it has a powerful std library which makes it much easier .
The main deal of go is concurrency support using go routines, which is Go's version of lightweight threads which are memory efficient and there is channels which help in safe communication and synchronisation between goroutines
Installing Golang
Installing golang is easy as any other software just search "Golang" and download it from their official website https://go.dev/
After downloading and installing Golang open your terminal and to verify the go installation enter the following command
go version
The output should look something like this.
If you see a message similar to the above one Go has been successfullyinstalled.
Puff!! That's it with installing Go.
Basic Data types in Golang
Golang is a statically typed language. This means that the compiler must know the type of each variable. So we have to explicitly declare them or code should be written in such a way that the compiler can infer the data type from the context.
The following are the different basic data types in golang:
bool
: It is used to represent the boolean datatype . It can only hold 2 values true or false
int, int8, int16, int32 , int64
: int is the most commonly used type to represent numbers it's size is platform depended 32bit for 32 bit systems and 64bits in 64bit systems , the rest are 8bits , 16bit , 32bits and 64bits respectively.
Type | Size | Range |
int | Depends on platform: 32 bits in 32 bit systems and 64 bit in 64 bit systems | -2147483648 to 2147483647 in 32 bit systems and -9223372036854775808 to 9223372036854775807 in 64 bit systems |
int8 | 8 bits/1 byte | -128 to 127 |
int16 | 16 bits/2 byte | -32768 to 32767 |
int32 | 32 bits/4 byte | -2147483648 to 2147483647 |
int64 | 64 bits/8 byte | -9223372036854775808 to 9223372036854775807 |
uint, uint8, uint16, uint32, uint64
: These are also the same as their int counterparts but the difference is that they represent unsigned numbers that is they start from 0 specified by the u
prefix
Type | Size | Range |
uint | Depends on platform: 32 bits in 32 bit systems and 64 bit in 64 bit systems | 0 to 4294967295 in 32 bit systems and 0 to 18446744073709551615 in 64 bit systems |
uint8 | 8 bits/1 byte | 0 to 255 |
uint16 | 16 bits/2 byte | 0 to 65535 |
uint32 | 32 bits/4 byte | 0 to 4294967295 |
uint64 | 64 bits/8 byte | 0 to 18446744073709551615 |
Type uintptr
in Golang is an integer type that is large enough to contain the bit pattern of any pointer. In other words, uintptr
is an integer representation of a memory address.
byte
: is an alias for the uint8 datatype
rune
: is an alias for int32 datatype . It is used in unicode representation
complex32
, complex64
: are used to represent complex numbers. They are rarely used.
string
: String datatype is used to store string literals . the underlying structure of string data type is a byte
slice (slice is go's version of list).
Thats all there is to Data types in golang!!
Subscribe to my newsletter
Read articles from Gautham Krishna directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gautham Krishna
Gautham Krishna
Backend Developer