Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created November 22, 2018 08:10
Show Gist options
  • Save jreisinger/3a8ae89aadcbebc64ecf93867ad8bc8d to your computer and use it in GitHub Desktop.
Save jreisinger/3a8ae89aadcbebc64ecf93867ad8bc8d to your computer and use it in GitHub Desktop.
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