Go Best Practices — Error handling
Sebastian Dahlgren
1545

Instead of the empty struct, you can also just do…

type ErrorZeroDivision string
func (e ErrorZeroDivision) Error() string {
return string(e)
}
func divide(a, b float64) (float64, error) {
if b == 0.0 {
return 0.0, ErrorZeroDivision("cannot divide by zero")
}
  return a / b, nil
}
func main() {
result, err := divide(1.0, 0.0)
fmt.Printf(`result: %+v, error: %+v`, result, err)
}