Go is a simple, fast, compiled language from Google. Ideal for CLI tools, API servers, and microservices.
Hello World and Structs¶
package main import “fmt” type User struct { Name string Email string Age int } func (u User) Greet() string { return fmt.Sprintf(“Hello, %s!”, u.Name) } func main() { user := User{Name: “Jan”, Email: “[email protected]”, Age: 30} fmt.Println(user.Greet()) }
Error Handling¶
func divide(a, b float64) (float64, error) { if b == 0 { return 0, fmt.Errorf(“division by zero”) } return a / b, nil } result, err := divide(10, 0) if err != nil { log.Fatal(err) }
HTTP Server¶
package main import ( “encoding/json” “net/http” ) func main() { http.HandleFunc(“/api/hello”, func(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(map[string]string{“message”: “Hello!”}) }) http.ListenAndServe(“:8080”, nil) }
Key Takeaway¶
Go is simple — you can learn it in a week. Error handling is explicit (if err != nil). Great for backend and CLI.