Getting started with GoLang: Tutorial for beginners

Geno Tech
3 min readJan 27, 2021

Here we go with Go. Go programming language was developed by Google in 2007. It was released in 2009 officially. Go is consists of high powerful libraries to achieve fast and high performances. It's an open-source programming language. We can develop applications easily and simply using it. Google had a purpose to develop a loosely-based language such as C. So, This is the result of that. Nowadays Go is using by many companies and getting popular day by day such as GitHub. Intel, Nokia, Mozilla, YouTube etc.

Here I explained the fundamentals of language structure. As a beginner of Go or expertise, whoever you can refresh your knowledge with this simple and complete explanation.

Table of Content

  1. Hello World
  2. Variables
  3. Switch Statements
  4. Arrays
  5. Functions

1. Hello World

“Hello World” is the first approach of all computer languages ever. There we check the SDK is installed correctly. You can install the Go SDK here. After you successfully installed it, next you need to implement your first code snippet as follows. Simply you can run this code snippet on you command prompt using go run file_name.go command. fmt.Println() command use to print something in console. The ‘P’ should be in capital and no need semicolon !!!

package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}

2. Variables

What are the variables? Variables are the primary data storing and data utilizing mechanism is every language. There have few types of variables such as Integer, Float, Double, Char, Boolean etc. Here I show you, How they are using with Go.

func main() {// Here you not need to mention the data type explicitly
var a = 123
fmt.Println(a)

var b int = 2
fmt.Println(b)

var c = true
fmt.Println(c)

var d string = "Simple data types"
fmt.Println(d)

}

3. Switch Statements

Switch statements are very important in programming. This is used to check the value of a variable and get actions according to.

var i = 2
switch i {

case 1:
fmt.Println("Value is 1")

case 2:
fmt.Println("Value is 2")

case 3:
fmt.Println("Value is 3")
}

4. Arrays

Arrays are the basic type of collections, used to store a set of variables(one type) in one variable. Languages already define the methods which are using with an Array such as length, get etc. Here I show you the array syntax with GoLang. Let’s see how to initialize and to declare a string array.

var a[2] string

a[0] = "One"
a[1] = "Two"

fmt.Println(a[0] , a[1])
fmt.Println(a)

// Output
One Two
[One Two]

5. Functions

The function is a set of tasks wrap into a single code block which we can use again and again when we want. The main() function we run already in every program. We can write any function using the following syntax in GoLang.

func main() {   var a = 10
var b = 20
var c int
c = add(a,b)
fmt.Println("Addition Function Result :", c)
}

func add(num1, num2 int) int{

var result int
result = num1 + num2
return result

}
// output
Addition Function Result : 30

Conclusion

At the end of the story, you have learned the basic syntaxes we are using in GoLang. I hope this short guide will help you to a happy journey with this. Comment you’re great ideas or ask any question has with this story in the response section below.
Found this post useful? Kindly tap the 👏 button below! :)

--

--

Geno Tech

Software Development | Data Science | AI — We write rich & meaningful content on development, technology, digital transformation & life lessons.