Go functions often return an error as their last return value. Callers check this error before using other results:
func divide(a, b int) (int, error) {
if b == 0 {
return 0, errors.New("division by zero")
}
return a / b, nil
}
When there's no error, return nil. When there is, return an error describing what went wrong. This pattern is everywhere in Go code. You'll use it constantly.