ConvertAPI / convertapi-library-go

A Go library for the ConvertAPI
https://www.convertapi.com
Other
14 stars 7 forks source link

Not very idiomatic Go #4

Closed tadvi closed 4 years ago

tadvi commented 4 years ago

This is small function and benefits might not be obvious.

Go way is to "prefer early return". That means returning from the function on error early. It also means checking for err != nil .

func AddErr(errs *[]error, err error) bool {
    if err == nil {
        return true
    } else {
        *errs = append(*errs, err)
        return false
    }
}

// idiomatic Go checks for err != nil // Also prefer "early return"

func AddErr(errs *[]error, err error) bool {
    if err != nil {
        *errs = append(*errs, err)
        return false
    }
    return true
}
JonasJasas commented 4 years ago

Fixed