Skip to content

Instantly share code, notes, and snippets.

@betandr
Last active July 8, 2020 13:56
Show Gist options
  • Save betandr/4e2e005c78cb756843f7e4d8b7e1343d to your computer and use it in GitHub Desktop.
Save betandr/4e2e005c78cb756843f7e4d8b7e1343d to your computer and use it in GitHub Desktop.
An interface is only considered nil if it is not associated with an underlying value, even a nil value.
package main
import "fmt"
type Error struct {
Message string
}
func (e *Error) Error() string {
return "an error occured"
}
func error1() error {
var e error
fmt.Println("error1: ", e == nil)
return e
}
func error2() error {
var e *Error
fmt.Println("error2: ", e == nil)
return e
}
func main() {
e1 := error1()
fmt.Println("e1: ", e1 == nil)
e2 := error2()
fmt.Println("e2: ", e2 == nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment