Go is a light-weight programming language developed by Robert Griesemer, Rob Pike and Ken Thompson at Google in the year 2007. But it was made available to everyone in the year 2009 as an open-source programming language. It has been awarded as TIOBE's Programming Language Hall of Fame winner for 2016 and it has gained popularity ever since. Syntactic wise, it is very similar to the C language. So the syntax will be pretty straight forward with no complex abstraction. Golang mainly targets server-side web development. It is being used in many projects at Google. Go has been used to build popular products like Docker, Kubernetes, Arduino-cli, etc.
Despite being a statistically typed language, it is very light and agile to use. It is a fully compiled language and the speed of execution is very high too. Golang maintains a good balance of performance and simplicity.
Want to Become a Master in Golang? Then visit here to learn Golang Certification Course from hkrtrainings.
Following are the functionalities of Golang,
Cross platform
Object Oriented
Concurrency
Multithreading
It is very easy to set up a Golang environment on your system. All we need is a Go compiler. The latest Go installable archive file will be available at Golang Installation The latest version of the Go language as of now is 1.14.4. Choose the installable file based on your operating system.
Download the MSI installer - go1.14.4.windows-amd64.msi which will configure the environment automatically. Run the downloaded MSI file and follow the prompts to install the tools. The Go distribution will be stored at C:\Go location in your local file system. The environment variable for Golang will be automatically set to C:\Go\bin.
Download the package file go1.14.4.darwin-amd64.pkg and open it. Follow the prompts to install the tools. The Go distribution will be stored at /usr/local/go location in your local file system. The environment variable path would be /usr/local/go/bin.
Download the tar archive file - go1.14.4.linux-amd64.tar.gz and extract its contents to /usr/local. Create a Go tree under /usr/local/go using the below command,
tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz
Set the environment variable by adding the below line to /etc/profile
export PATH=$PATH:/usr/local/go/bin
Note: Once the installation is done, the command prompts that are already open in your system should be restarted for the change to take effect.
First, set up a Go workspace in your system. If your OS is Linux/Mac, the workspace should be at $Home/go. If your OS is Windows, then the workspace should be created at C:\Users\YourName\go.
Open a text editor and copy the below code,
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
Save the program as helloworld.go
To run the above program, open a command prompt and execute the below command,
go run workspace path/helloworld.go
The workspace path in the above command would be the path of the workspace created earlier.
Once you run the program, Hello World will be printed on the console.
To declare a variable in Go, we don’t have to declare its type. It will automatically assign the type based on the initialized value of the variable.
For example, var a = 10. The variable a will be inferred with the type int
Let’s take a look at the available data types in Golang,
Numeric
Derived
Note: Unlike C language, Go does not allow automatic type conversion.
Conditional statements
if
switch
Loops
If you have any doubts on Golang, then get them clarified from Golang Industry experts on our Golang community!
Exception handling is the process of handling errors using built-in error types. It doesn’t have try/catch methods. The errors in Go are represented using the type error. If there are no errors found, it returns a value of nil.
Go is an easily understandable language so the developers don’t have to invest too much of their time in learning. It has a stable syntax and the code is easy to maintain too. It is mainly built to make a programmer’s life easier. So it is a language worth learning.
Batch starts on 6th Jun 2023, Weekday batch
Batch starts on 10th Jun 2023, Weekend batch
Batch starts on 14th Jun 2023, Weekday batch