Back to course

Functions: Multiple Return Values

Go (Golang) for Cloud-Native Microservices

Go Functions

Functions are first-class citizens in Go. A unique feature is returning multiple values.

Pattern: (Result, Error)

In Go, we don't use try/catch. We return errors. go func divide(a, b float64) (float64, error) { if b == 0 { return 0, fmt.Errorf("cannot divide by zero") } return a / b, nil }

Always check errors immediately: if err != nil { ... }.