Created
November 22, 2018 08:10
-
-
Save jreisinger/3a8ae89aadcbebc64ecf93867ad8bc8d to your computer and use it in GitHub Desktop.
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" | |
"time" | |
) | |
// Anything that has Error() function is an Error, i.e. satisfied the Error | |
// interface. | |
type MyError struct { | |
what string | |
when time.Time | |
} | |
func (m MyError) Error() string { | |
return fmt.Sprintf("%s at %s", m.what, m.when) | |
} | |
func main() { | |
err := MyError{} | |
err.what = "Bad thing" | |
err.when = time.Now() | |
fmt.Printf("%v\n", err) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment