Contents

Go Tutorial Part 1 - Introduction

1 Why Go?

  1. Golang is an open source statics typed, compiled language.
  2. It finds a sweet-spot between easy to use and stay powerful
  3. This will be a series of posts that will help understand the language and it’s powers

2 Setting Up

  1. Download and Install Go from the official website
  2. Type GO in terminal to make sure go was installed correctly
  3. Install a code editor
  4. If VSCODE then install the go extension and make sure the addons are installed with it.

3 A simple Go program

package main

import "fmt"

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

Now save the program as hello.go

4 Running the program

  1. Open a Terminal and navigate to the directory in which you saved the program
  2. Type go run hello.go
  3. You should see Hello World! printed

5 Diving Deep

5.1 package main

  1. package is like a workspace or project
  2. package is a collection of source code files.
  3. package per application
  4. Each file in the package should declare the package on the top like package main
  5. Two types of packages - executable and reuseable
  6. Executable package:
    1. Generates a file that we can run
    2. Has package name as main
    3. Must have a function named main
  7. Reuseable package:
    1. To be imported and used in other projects
    2. Does not create an executable when build
    3. Does not use the package name as main

5.2 import "fmt"

  1. Giving our package access to code written in other package
  2. fmt is a package that helps format the code better
  3. Check official docs for more details.

5.3 func main

  1. func is short for function
  2. Similar in functionality to function in any other programming language