Can anyone please help me understand why "if err == errEOF" is not evaluating to TRUE and its only works with io.EOF. I know the Strings.Read function is returning io.EOF, but why can't we use the same type and value to evaluate the err?
https://play.golang.org/p/bCp4bZjKW-K
package main
import (
"errors"
"fmt"
"strings"
"io"
)
var errEOF = errors.New("EOF")
func main() {
r := strings.NewReader("ABCDEFGH")
buf := make([]byte, 4)
for {
n, err := r.Read(buf)
fmt.Println(n, err, buf[:n])
//if err == io.EOF { //Loop is breaking only when i use io.EOF
if err == errEOF { // If i use my own ErrEOF value, It is Not Breaking, Going forever
break
}
}
}