Go function to test whether a file exists How could one write in a more elegant way that if error is null, the result is true? I really need a bool as returned value.

func existsFile(pPath string) bool {
    _, errStat := os.Stat(pPath)

    if errStat != nil {
        return false
    }
    return true
}
Instead of checking with an if statement if errStat is null and then returning false:


if errStat != nil {
    return false
}
return true



you can return a Boolean expression:

return errStat == nil