Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Created July 16, 2012 20:14
Show Gist options
  • Save larzconwell/3124760 to your computer and use it in GitHub Desktop.
Save larzconwell/3124760 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
type MyError struct {
When time.Time
Type, Message string
}
func (e *MyError) Error() string {
return fmt.Sprintf("Error[%s]: %s <%v>",
e.Type, e.Message, e.When)
}
func run() (str string, err error) {
time := time.Now()
str = ""
err = nil
if time.Minute() < 30 {
err = &MyError{time, "TimeError", "You're under 30 minutes!"}
} else {
str = "Past 30 minutes!"
}
return
}
func main() {
str, err := run()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(str)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment