The standard error handling pattern:
result, err := doSomething()
if err != nil {
return fmt.Errorf("doing something: %w", err)
}
// Use result
Check immediately, wrap with context, return. Keep the happy path at the left margin. Error handling is indented.