Go (often referred to as Golang) is an open-source programming language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It was designed to solve common problems in software engineering, such as slow compilation, complex dependency management, and difficult concurrency.
The guiding principle of Go is simplicity over complexity. It intentionally leaves out features common in other languages (like classes, inheritance, or assertions) to keep the code readable and maintainable.
Fast: It compiles directly to machine code (like C++), making it very efficient.
Simple: The syntax is clean and easy to learn.
Safe: It is statically typed and memory-safe with built-in garbage collection.
Go is famous for how it handles multiple tasks at once. Instead of heavy "Threads," Go uses Goroutines, which are incredibly lightweight. You can run hundreds of thousands of them simultaneously without crashing the system.
Go has a "batteries-included" approach. Its standard library is powerful enough to build a full web server or handle complex cryptography without ever needing to download a third-party framework.
Go offers the safety of a statically typed language (like Java) but feels as fast to write as a dynamic language (like Python). It produces a single static binary, meaning you don't need to install a runtime on the server to run your app—you just drop the file and go.
Go has become the "language of the Cloud." It is the primary language used to build:
Cloud Infrastructure: Docker, Kubernetes, and Terraform are all written in Go.
Microservices: High-speed APIs that need to scale.
DevOps Tools: Fast, CLI-based utilities.
Data Processing: Efficiently handling massive streams of data.
package main
import (
"fmt"
"os"
)
// multiplyRoutine performs the calculation and sends the result back through a channel
func multiplyRoutine(a, b float64, resultChan chan float64) {
result := a * b
resultChan <- result // Send data to the channel
}
func main() {
var num1, num2 float64
// 1. Accept 2 numeric inputs
fmt.Print("Enter first number: ")
fmt.Scan(&num1)
fmt.Print("Enter second number: ")
fmt.Scan(&num2)
// 2. Create a channel for communication
resultChan := make(chan float64)
// 3. Start the routine
go multiplyRoutine(num1, num2, resultChan)
// 4. Receive the result (this waits until the routine is done)
result := <-resultChan
// 5. Output to Display Screen
fmt.Printf("\n--- Display Output ---\n")
fmt.Printf("The result of %.2f * %.2f is: %.2f\n", num1, num2, result)
// 6. Output to "Printer" (Creating a physical file)
err := os.WriteFile("printer_output.txt", []byte(fmt.Sprintf("RESULT: %.2f", result)), 0644)
if err != nil {
fmt.Println("Error sending to printer:", err)
} else {
fmt.Println("\n[Success] Result sent to printer (printer_output.txt)")
}
}