package learning import ( "fmt" "time" ) // Declaring MyError structure type MyError struct { When time.Time What string } // Declaring pointer method for MyError called Error that returns string func (e *MyError) Error() string { return fmt.Sprintf("at %v, %s", e.When, e.What) } // error type: default go interface for returning string with error func run() error { // Returning pointer to new instance of MyError with provided arguments return &MyError{ time.Now(), "it didn't work!", } } func ErrorLearning() { // Checking that error, returned from run() is not equal to nil if err := run(); err != nil { // Printing created error to fmt fmt.Println(err) } } i,err := strconv.Atoi("42")