Shifna Zarnaz

Common Mistakes and Issues Faced in Go Programming

Hi All,

If u are about to kickstart your career as a golang developer,then this blog is gonna really help you

When starting career as a developer,it is a quite common to face some issues and trying to rectify or solve those issues.

So let me share some common issues faced by me as a developer and the causes and the ways I followed to solve this issue with clear cut explanation with screenshots

1.Invalid Memory or Nil-Pointer deference

                    panic: runtime error: invalid memory address or nil pointer dereference
                    [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x126af9f]

Your code may be syntactically correct.But when you are running your code,you may get this kind of issues.

This may be due to many reasons like

To determine the root cause of the issue, you need to examine the code and look for potential problems such as:

  • Nil pointers: Check if any pointers are nil when they are dereferenced. Make sure all necessary pointers are properly initialized and not set to nil.
  • Uninitialized variables: Ensure that all variables used in the code are initialized with valid values before they are accessed.
  • Incorrect API usage: Review the documentation and usage examples of the package to verify that the List function is used correctly. Check if any necessary parameters or options are missing.

Let me show you with the eg..

Here ,When am calling the function with this argument..

I got panic error,as shown below

                    panic: runtime error: invalid memory address or nil pointer dereference
                    [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x126af9f]  Reason for this issue

When I pass the correct argument, code runs perfectly

Here I have passed the clientset as a argument,instead of using k8s package clientset.

So need to pass the proper arguments ,if not these kind of issues can occur.

2. Not able to use the members of auto-generated code

This is the struct of auto-generated code

But when I am trying to use this struct in the code,am not able to use the updated struct which is generated .

This is because,the changes are not pushed in git.Inorder to solve this issue,you can use the below command for creating workspace.

                    go work init
                    go work ./folders_name

With the above command,workspace is created and these kind of issues can be solved.

3. While using the package of git which is from private repo:

When you are trying to use the package from private repo,you will face below issue

                    remote: Repository not found

To Solve this issue,follow the below steps:

  • 1. Get the access for that private repo
  • 2. edit the file ~/.gitconfig
  • 3. [url “ssh://”]

insteadOf =

Add these lines in the gitconfig as you can see below:

Then export the pkg with the below command

                    export GOPRIVATE=pkg_name

Other issues

As a beginner in the field of golang developer,you can also face below issues:

1. Incorrect use of pointers:

Go has a straightforward approach to pointers, but mishandling them can lead to unexpected behavior. We explain the concept of pointers in Go and provide an example to showcase proper usage.

                    func incrementValue(x *int) {
                      *x++ // Correctly dereference the pointer to modify the value
                  func main() {
                      value := 10
                      incrementValue(&value) // Pass the address of value using the '&' operator
                      fmt.Println(value) // Output: 11

2. Failure to handle errors properly:

Go encourages explicit error handling using the built-in error type. Neglecting to handle errors or ignoring error return values can lead to program crashes or incorrect behavior. We discuss the importance of error handling and provide examples of best practices.

                    func divide(x, y int) (int, error) {
                      if y == 0 {
                          return 0, fmt.Errorf("division by zero") // Return an error when dividing by zero
                      return x / y, nil
                  func main() {
                      result, err := divide(10, 0)
                      if err != nil {
                          fmt.Println("Error:", err) // Output: Error: division by zero

3. Improper use of goroutines and channels:

Go’s concurrency model relies on goroutines and channels. Mishandling goroutines can result in race conditions, deadlocks, or excessive resource consumption. We delve into the correct usage of goroutines and channels and highlight potential pitfalls to avoid.

                    func main() {
                      messages := make(chan string)
                      go func() {
                          messages <- "Hello" // Send a message to the channel
                      msg := <-messages // Receive the message from the channel
                      fmt.Println(msg) // Output: Hello

4. Inefficient use of slices:

Slices are a powerful feature in Go, but inefficient use can impact performance. We explore common mistakes such as unnecessary copying and inefficient appending within loops. We provide tips on how to write more efficient code when working with slices.

                    func sum(numbers []int) int {
                      total := 0
                      for _, num := range numbers {
                          total += num
                      return total
                  func main() {
                      numbers := []int{1, 2, 3, 4, 5}
                      result := sum(numbers)
                      fmt.Println(result) // Output: 15

5. Incorrect Handling of Interface Types: Go’s interface types allow for flexible and polymorphic behavior. However, improper handling can result in panics or type mismatches. We provide examples and best practices for working with interfaces in Go.

6. Lack of Code Organization and Structure: Go places importance on code organization and structure. Neglecting to follow recommended package layouts or failing to separate concerns can make code maintenance challenging. We discuss the importance of code organization and offer guidance on structuring Go code effectively.


By being aware of these common mistakes and issues in Go programming and following best practices, developers can write more robust, efficient, and maintainable code. Avoiding these pitfalls enhances code quality, reduces bugs, and improves overall productivity. Embracing the simplicity and elegance of Go, along with proper practices, enables developers to leverage the language’s strengths and build high-quality applications.