Created
August 19, 2016 20:36
-
-
Save roustem/a842ef53b9f3ff60e4a176a3535081dc to your computer and use it in GitHub Desktop.
Go interface issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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