DEV Community

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

Posted on

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

#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, we got to know about the structure of a Go project and how to set it up locally.

Also, in this post, I will be going through OSS projects for better understanding.

Structure of Lazygit

Lazygit is a terminal UI for git.

This has 70k+ stars on GitHub.

This project is a good example of how it works in a real-world use case.

In the go.mod file, there is use of:

module github.com/jesseduffield/lazygit

go 1.25.0

// This is necessary to ignore test files when executing gofumpt.
ignore ./test

require (
    dario.cat/mergo v1.0.1
    github.com/adrg/xdg v0.4.0
.....
.....
.....
)

Enter fullscreen mode Exit fullscreen mode

lazygit is the name of the project, prefixed by the code hosting provider github.com, and jesseduffield is the username or it can be an organization name.

This project needs a minimum Go version of 1.25.0.

Under the require section, there are many packages listed. These are the dependencies of this project.

The dependency can be a package or it can be a library.

This is added when we run the go get <package-name> command.

If any new person clones this project, they can run the go mod tidy command to install all the dependencies at once.

Understanding the Code Structure

Let's go back to simple code:

package main

import "fmt"

func main() {

    fmt.Println("Hello, World!")

}

Enter fullscreen mode Exit fullscreen mode

Any *.go extension will have a package defined in the script.

The rule is if we want the script to be executable, it should have package main and func main().

This rule exists because execution must have an entry point for the functions. That means any executable must have an entry point for the functions.

It has a directory structure which is not needed for now as we are just starting.

import is used to import packages. In the above code, we are importing the fmt package, which is from the standard library. This will already be ready with the Go runtime. We don't have to explicitly define it.

The fmt package is used for printing and formatting string operations.
Println is a function in the fmt package which is used to print the output.

Conclusion

We learned about how the go.mod file will help us to manage dependencies and manage minimum versions of Go to run this project, and we also learned about how a module is defined.

We actually checked the OSS project lazygit to understand the structure.

We moved into understanding the code structure and understood the package in Go and how to define it based on our requirement.

Coming Next

Understanding the standard library and function calling in Go.


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)