>_ Golang Step By Step
Intern

Hello, World!

Write and run your first Go program

# What is Go?

Go (also called Golang) is an open-source programming language created at Google in 2009 by Robert Griesemer, Rob Pike, and Ken Thompson. It was designed to be simple, fast, and reliable — perfect for building web servers, CLI tools, and large-scale distributed systems.

Go compiles directly to machine code (no virtual machine), has built-in concurrency support, garbage collection, and a deliberately small language specification. If you're coming from Python or JavaScript, Go will feel much more structured. If you're coming from C++ or Java, Go will feel refreshingly simple.

More Details (Real-World Example)click to expand

Think of Go like a well-organized modern kitchen in a busy restaurant. Every tool has a clear purpose, everything is placed in a predictable spot, and the team follows simple repeatable rules. This helps chefs (developers) move fast without confusion.

In the same way, Go keeps syntax small and explicit so engineers can read production code quickly. At companies building APIs, payment systems, or cloud services, this clarity reduces mistakes during on-call incidents because teams can understand code paths fast.

Your first main() program is like opening the kitchen each morning: you start in one place, follow a known sequence, and produce predictable output.

# Your First Go Program

Every Go program follows a strict structure. Let's look at the simplest possible program:

package main

import "fmt"

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

Output: Hello, World!

# Breaking It Down

package main

Every Go file starts with a package declaration. The package named main is special — it tells Go this file is an executable program, not a library.

import "fmt"

The import keyword brings in packages you need. The fmt package (short for "format") provides functions for formatted I/O like printing to the console.

func main() { }

The main() function is the entry point of your program. When you run the program, Go starts executing code from here. Every executable must have exactly one main() function in the main package.

fmt.Println("Hello, World!")

This calls the Println function from the fmt package. It prints the text followed by a newline. Notice the capital "P" — in Go, exported (public) functions start with an uppercase letter.

# More Examples

Printing multiple values

package main

import "fmt"

func main() {
    fmt.Println("Hello", "World", 2026)
    // Output: Hello World 2026
    // Println adds spaces between values automatically
}

Using Printf for formatted output

package main

import "fmt"

func main() {
    name := "Gopher"
    fmt.Printf("Hello, %s! Welcome to Go.\\n", name)
    // Output: Hello, Gopher! Welcome to Go.
}

Multiple imports

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("Current time:", time.Now())
}

When importing multiple packages, use parentheses to group them. This is called a "factored import statement".

# How to Run Your Program

Save your code in a file called main.go, then use the terminal:

# Run directly (compile + execute in one step)
$ go run main.go
Hello, World!

# Or build a binary first, then run it
$ go build -o hello main.go
$ ./hello
Hello, World!

⚡ Key Takeaways

  • Every executable Go program needs package main and a main() function
  • Use import to bring in packages — fmt is for printing
  • Exported functions start with an uppercase letter (e.g., Println)
  • go run compiles and runs; go build creates a binary
practice & review