Exploring Golang: Getting Started
A Beginner's Journey into Coding, Testing, and Concurrency"

Forward-thinking IT Operations Leader with cross-domain expertise spanning incident & change management, cloud infrastructure (Azure, AWS, GCP), and automation engineering. Proven track record in building and leading high-performance operations teams that drive reliability, innovation, and uptime across mission-critical enterprise systems. Adept at aligning IT services with business goals through strategic leadership, cloud-native transformation, and process modernization. Currently spearheading application operations and monitoring for digital modernization initiatives. Deeply passionate about coding in Rust, Go, and Python, and solving real-world problems through machine learning, model inference, and Generative AI. Actively exploring the intersection of AI engineering and infrastructure automation to future-proof operational ecosystems and unlock new business value.
Introduction:
As an Infrastructure Monitoring engineer aspiring to transition into the world of DevOps so I am learning a programming language that aligns with the current demand in the market. In this article, I will talk about my favorite programming language Golang or Go. It's a powerful language known for its simplicity, performance and excellent support for concurrent programming. I will cover the basics of Golang, provide code snippets, and discuss how to test a basic Golang application. Additionally, I'll touch upon concurrency, Goroutines, and channels, which are essential concepts in Go programming. So, let's dive in!
Why Golang for DevOps?
Golang has gained popularity in the DevOps community due to its efficiency in building scalable, concurrent, and robust applications.
Here are a few reasons why Golang is an excellent choice for DevOps:
Simplicity: Golang offers a clean and straightforward syntax, making reading and writing code easy, especially for beginners.
Performance: Golang's compilation process produces statically linked binaries, resulting in highly performant applications.
Concurrency: Go provides built-in support for concurrency, allowing developers to handle concurrent tasks and maximize resource utilization efficiently.
Standard Library: Golang comes with a rich standard library that offers comprehensive functionalities, including network programming, file handling, testing, and more.
Getting Started with Golang:
Let's cover the basics of Golang by exploring a simple "Hello, Gopher!" program.
package main
import "fmt"
func main() {
fmt.Println("Hello, Gopher!")
}
go run main.go
Hello, Gopher!
The package main statement indicates that this is the main package, and it should be an executable program.
import "fmt" imports the "fmt" package, which provides functions for formatted I/O operations.
func main() is the entry point of the program.
fmt.Println("Hello, Gopher!") prints the string "Hello, Gopher!" to the standard output.
Test Hello, Gopher!:
Testing is an essential aspect of software development. Golang provides a robust testing framework as part of its standard library.
Let's write a basic test for our "Hello, Gopher!" program.
package main
import (
"fmt"
"testing"
)
func TestHelloGopher(t *testing.T) {
expected := "Hello, Gopher!"
result := HelloGopher()
if result != expected {
t.Errorf("Expected %q, but got %q", expected, result)
}
}
func HelloGopher() string {
return "Hello, Gopher!"
}
func main() {
fmt.Println(HelloGopher())
}
go test main_test.go
ok command-line-arguments 0.074s
We added a new function TestHelloWorld with a *testing.T parameter, which allows us to perform tests.
Inside TestHelloWorld, we define the expected output and call helloWorld() to obtain the actual result.
If the result differs from the expected value, we use t.Errorf to report an error.
By running go test command, Golang executes all the tests within the package.
Concurrency with Goroutines and Channels:
Concurrency is a crucial aspect of modern software development. Golang provides powerful mechanisms like Goroutines and channels to handle concurrent tasks effectively.
Let's explore a simple example to understand their usage.
package main
import (
"fmt"
"time"
)
func main() {
messages := make(chan string)
go func() {
time.Sleep(2 * time.Second)
messages <- "Hello from Goroutine!"
}()
fmt.Println("Waiting for message...")
msg := <-messages
fmt.Println(msg)
}
go run main.go
Waiting for message...
Hello from Goroutine!
Created a channel, messages using the make function.
Inside a Goroutine, sleep for 2 seconds and then send a message to the channel using the <- operator.
The main Goroutine waits for a message from the channel using <-messages, which blocks until a message is received.
Finally, the received message is printed to the console.
In this article, I covered the basics of Golang with a "Hello, Gopher!" example, explored testing a basic Golang application, and touched upon concurrency with Goroutines and channels.
Thank you for reading this far. In the coming days, I will come up with more such articles on Golang. I will dive deeper into the world of programming using Golang.
Till then, Happy Coding!




