Getting started with GoLang: Tutorial for beginners

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

var b int = 2

var c = true

var d string = "Simple data types"


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])

// 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


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! :)

Mobile I Web I Data Science I AI — We write rich & meaningful content on development, technology, digital transformation & life lessons.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store