package main import ( "fmt" "io" "log" "runtime" ) // close a Closer or panic. better than just close, object scoping safe func closeOrPanic(c io.Closer, description string) { if err := c.Close(); err != nil { panic("Could not close '" + description + "': " + err.Error()) } } // close and ignore any error func closeIgnore(c io.Closer) { // we simply ignore any error _ = c.Close() } // close or log the failure. need to provide the %s in format func closeOrLog(c io.Closer, format string) { if err := c.Close(); err != nil { log.Printf(format, err) } } // return a nice not yet implemented error func notYetImplemented() error { pc, _, _, ok := runtime.Caller(1) if ok == false { return fmt.Errorf("notYetImplemented() cshould not be called from static context") } return fmt.Errorf("%s is not yet implemented", runtime.FuncForPC(pc).Name()) }