What is Go?
Go (also called Golang) is an open-source programming language developed by Google. Created by Robert Griesemer, Rob Pike, and Ken Thompson, it was designed for simplicity, efficiency, and ease of use in modern software development.
Key Features:
- Simple Syntax: Easy to learn and read
- Fast Compilation: Compiles to native machine code
- Built-in Concurrency: Goroutines and channels
- Garbage Collected: Automatic memory management
- Strong Standard Library: Excellent networking, HTTP, JSON support
Where Go is Used:
- Cloud services (Docker, Kubernetes)
- Web backends and APIs
- Command-line tools
- DevOps and infrastructure
- Microservices
Go's Philosophy:
- Simplicity over cleverness
- One way to do things
- Explicit over implicit
- Composition over inheritance
Code Examples
Hello Worldgo
package main
import "fmt"
func main() {
// Print to console
fmt.Println("Hello, World!")
// Variables
var name string = "Go"
version := 1.21 // Short declaration with type inference
fmt.Printf("Welcome to %s %.2f!\n", name, version)
// Multiple return values (common in Go)
result, err := divide(10, 2)
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("Result:", result)
}
}
func divide(a, b float64) (float64, error) {
if b == 0 {
return 0, fmt.Errorf("cannot divide by zero")
}
return a / b, nil
}Go emphasizes simplicity. Note the := for short variable declaration and multiple return values for error handling.
Quick Quiz
1. What does := do in Go?
Was this lesson helpful?