Getting Started with Go: A Beginner’s Guide 2024

Tejaksha K
2 min readApr 17, 2024

--

If you’re venturing into the realm of Go (Golang) programming, you’re in for an exciting journey into a powerful language designed for simplicity and efficiency. Let’s kickstart your Go adventure with a step-by-step guide to setting up your first project and printing your inaugural “Hello World.”

Step 1: Initialising Your Project or Module

Before diving into the coding fray, let’s lay the groundwork for your Go project. Open your terminal and create a new file named main.go. In the terminal, run the following command:

go mod init your-app

This command initialises a Go module named your-app within your project directory, enabling dependency management for your project.

Step 2: Creating the Entry Point for Your Application

In Go, every executable program begins with a main function. This function serves as the entry point for your application, where the execution starts. Let's define this function in your main.go file:

package main

func main() {
// Your code will go here
}

Step 3: Adding Packages

Go operates with the concept of packages, which are used to organize code into reusable modules. Packages provide a way to structure your programs and manage dependencies efficiently. Let’s import the fmt package, which provides functions for formatting and printing output:

package main

import "fmt"

func main() {
// Your code will go here
}

Step 4: Printing “Hello, World!”

Now, let’s put our newfound knowledge into action by printing the classic “Hello, World!” message to the console. We’ll leverage the Println function from the fmt package:

package main

import "fmt"

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

Congratulations! You’ve successfully written your first Go program. Save your main.go file, and in your terminal, navigate to the directory containing your project. Then, execute the following command to run your Go program:

go run main.go

You should see the glorious message “Hello, World!” printed to your console, marking the beginning of your journey into the wonderful world of Go programming.

Stay tuned for more exciting adventures in Go! Happy coding! 🚀🔍

BONUS SECTION

Tutorials of my suggestion to start with GO lang

  1. https://tinyurl.com/go-lang-course
  2. https://tinyurl.com/go-lang-nana

--

--

Tejaksha K
Tejaksha K

Written by Tejaksha K

I'm a Full Stack Developer & Cloud Expert with experience in Google Cloud Platform & AWS.

No responses yet