DEV Community

Cover image for Go Programming Language: Everything You Need To Know About It (Part 2)
Ganesh Kumar
Ganesh Kumar

Posted on

Go Programming Language: Everything You Need To Know About It (Part 2)

#go

Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a single platform for all development tools, cheat codes, and TL;DRs — a free, open-source hub where developers can quickly find and use tools without the hassle of searching the internet.

In my previous post, I explained Go's history, why it was created, what problems it solves, and its features.

In this post, I will be explaining the structure of a Go project, how to set it up locally, and how to run it.

So, let's not waste time on installation; you can install it using a single command:

curl -fsSL https://hexmos.com/ipm-install | bash && ipm i golang-go

Enter fullscreen mode Exit fullscreen mode

Structure

This structure consists of the files required to run your code.

Initialize a Go project by creating a go.mod file:

go mod init <project-name>

Enter fullscreen mode Exit fullscreen mode

This will create go.mod. Next, create a main.go file:

my-project/
├── go.mod
├── main.go
└── ...

Enter fullscreen mode Exit fullscreen mode

The go.mod file will contain:

module <project-name>

Enter fullscreen mode Exit fullscreen mode

The first line of go.mod contains the project name. The name should be unique depending on the code hosting provider (e.g., GitHub, GitLab).

This is necessary because Go code can be used in two ways:

  1. Executable: This is when you run the code directly using go run main.go.
  2. Library (Package): This is when you use the code in other projects by importing it.

You will also see the Go version specified:

go 1.23

Enter fullscreen mode Exit fullscreen mode

This indicates the Go version used to run the project.


First Go Program

main.go

package main

import "fmt"

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

Enter fullscreen mode Exit fullscreen mode

Run the code above with:

go run main.go
Enter fullscreen mode Exit fullscreen mode

In Next Post

We will be leanring by actually checking few open source projects for better understanding.


FreeDevTools

I’ve been building for FreeDevTools.

A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction when searching for tools and materials.

Any feedback or contributions are welcome!

It’s online, open-source, and ready for anyone to use.

👉 Check it out: FreeDevTools

⭐ Star it on GitHub: freedevtools

Top comments (0)