What is Go?
Go (also known as Golang) is a statically typed, compiled programming language designed at Google. It emphasizes simplicity, efficiency, and built-in support for concurrent programming through goroutines and channels.
Quick Facts
| Full Name | Go Programming Language |
|---|---|
| Created | 2009 by Google (Griesemer, Pike, Thompson) |
| Specification | Official Specification |
How Go Works
Go was created by Robert Griesemer, Rob Pike, and Ken Thompson at Google in 2007 and publicly released in 2009. It was designed to address criticisms of other languages while maintaining their positive characteristics. Go features fast compilation, garbage collection, structural typing, and CSP-style concurrency. The language has a minimal syntax with only 25 keywords, making it easy to learn. Go is particularly popular for building cloud infrastructure, microservices, CLI tools, and network servers. Notable projects written in Go include Docker, Kubernetes, and Terraform.
Key Characteristics
- Statically typed with type inference
- Fast compilation to native machine code
- Built-in concurrency with goroutines and channels
- Garbage collected memory management
- Simple syntax with only 25 keywords
- Excellent standard library
Common Use Cases
- Cloud infrastructure and DevOps tools
- Microservices and APIs
- Command-line tools
- Network servers and proxies
- Distributed systems
Example
package main
import (
"fmt"
"time"
)
// Struct definition
type User struct {
ID int
Name string
}
// Method on struct
func (u User) Greet() string {
return fmt.Sprintf("Hello, %s!", u.Name)
}
// Goroutine example
func worker(id int, jobs <-chan int, results chan<- int) {
for j := range jobs {
fmt.Printf("Worker %d processing job %d\n", id, j)
time.Sleep(time.Second)
results <- j * 2
}
}
func main() {
user := User{ID: 1, Name: "John"}
fmt.Println(user.Greet())
// Concurrent processing
jobs := make(chan int, 5)
results := make(chan int, 5)
go worker(1, jobs, results)
for i := 1; i <= 3; i++ {
jobs <- i
}
close(jobs)
}