Published on

Introduction to Go Programming Language

Introduction to Go Programming Language

Go: Understand Basics in Details

What is Go?

Go, also known as Golang, is a statically typed, compiled programming language designed at Google. It was developed to address the limitations of existing programming languages and to provide better performance and scalability for large-scale projects. Go is a high-level language, which means it is easy to learn and use, yet it is also capable of delivering highly efficient results.

Key Features of Go

  1. Simplicity: Go has a clean syntax that is easy to read and write. This makes it easier for developers to get started with the language and to write efficient code.
  2. Concurrency: Go was designed with concurrency in mind. It provides a powerful mechanism for handling multiple tasks at once, making it ideal for applications that need to handle large amounts of data or perform complex computations.
  3. Performance: Go is a statically typed language, which means that it is compiled rather than interpreted. This leads to faster performance and better scalability compared to dynamically typed languages.
  4. Standard Library: Go has a comprehensive standard library that includes a wide range of functionality, from basic data structures to complex algorithms.
  5. Open-source: Go is an open-source language, which means that developers have access to the source code and can contribute to the development of the language.

Getting Started With Go

To start with Go you can install go in your system from here and check version

    go version

Once Go installed in your computer we will write our first program in Go.

1. Hello World in Go

To create a first program in go create a file hello-world.go with below content. Code in Go is made up of tokens. A token is a keyword, a name (identifier), symbol, operator, string etc.

package main
import "fmt"
func main() {
    fmt.Println("Hello World")

To run this program

$ go run hello-world.go
--> hello world

// build this into binaries

$ go build hello-world.go
$ ls
hello-world    hello-world.go
execute the built binary directly
$ ./hello-world
--> hello world

2. Go Packages

In go every program is part of package and we define this using the package keyword. In hello-world.go example the program belongs to main package and in import ("fmt") lets us import files included in the fmt package.

3. Go Statements

Go Statements ends by ; or ending of a line, for ex fmt.Println("Hello World")

4 Go Comments

comments are text which ignored upon execution.

In Go you can write single line comments using // and multi-line comments start with /* and ends with */.

package main
import ("fmt")

func main() {
  // This is a comment in Go
  fmt.Println("Single line comment!")

  /* The multi line
  comment */
  fmt.Println("Multi line comment!")

5. Go Values

Go has different types of values int, float32, bool, string etc.

6. Declaring a Variable in Go

// we have to tell type
var variable_name type = value

// type of variable is inferred from the value 
variablename := value

// without assigning any value 
var a string
var b int
var c bool

Let's take one example to understand this

package main
import "fmt"
func main() {
    var b bool = true //type is bool
    var x float32 = 123.78 //type is float32
    var name1 string = "John" //type is string
    var name2 = "Jane" //type is inferred
    x := 2 //type is inferred

7. Functions in Go

8. Methods in Go

9. Strings and Runes in Go

10. interface in Go

11. Pointers in Go

12. Slice in Go

13. Method Chaining in Go

14. Recursion in Go

Applications of Go

Go is used in a wide range of applications, from web development and data analysis to machine learning and system programming. Some of the most popular applications of Go include:

  1. Web Development: Go is used to build fast and scalable web applications. It provides a robust set of tools and libraries for building HTTP servers and web applications.
  2. Network Programming: Go's concurrency mechanisms make it ideal for network programming. It is used to build networked applications and systems, such as proxies, routers, and firewalls.
  3. Data Analysis: Go is used for data processing and analysis, especially when dealing with large datasets. It provides efficient algorithms for working with data, making it ideal for data scientists and engineers.
  4. Machine Learning: Go is used for building machine learning models, including deep learning algorithms. It provides efficient tools for training and evaluating models, making it ideal for machine learning researchers and practitioners.
  5. System Programming: Go is used for system programming, such as building operating systems and system utilities. It provides a low-level interface to the underlying hardware, making it ideal for system programming tasks.


Go is a powerful, efficient, and easy-to-learn programming language that is well-suited for a wide range of applications. Whether you are a beginner or an experienced programmer, Go provides a rich set of tools and libraries to help you build robust and scalable applications. Whether you are looking to build web applications, analyze data, develop machine learning models, or write system utilities, Go is the right choice for you.