Source file tour/methods/errors.go
1 //go:build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "time" 8 ) 9 10 type MyError struct { 11 When time.Time 12 What string 13 } 14 15 func (e *MyError) Error() string { 16 return fmt.Sprintf("at %v, %s", 17 e.When, e.What) 18 } 19 20 func run() error { 21 return &MyError{ 22 time.Now(), 23 "it didn't work", 24 } 25 } 26 27 func main() { 28 if err := run(); err != nil { 29 fmt.Println(err) 30 } 31 } 32