Skip to content

Instantly share code, notes, and snippets.

@roustem
Created August 19, 2016 20:36
Show Gist options
  • Save roustem/a842ef53b9f3ff60e4a176a3535081dc to your computer and use it in GitHub Desktop.
Save roustem/a842ef53b9f3ff60e4a176a3535081dc to your computer and use it in GitHub Desktop.
Go interface issue
package main
import "fmt"
type MyError struct {
Message string
}
func (m *MyError) Error() string {
return m.Message
}
func errorMaker() error {
return nil
}
func myErrorMaker() (int, *MyError) {
return 1, nil
}
func main() {
err := errorMaker()
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("No error")
}
// will only be broken if myErrorMaker() returns more than 1 value
x, err := myErrorMaker()
if err != nil {
fmt.Println("Error:", err)
} else {
fmt.Println("No error:", x)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment