]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: add Errorf helper function
authorAndrew Gerrand <adg@golang.org>
Fri, 1 Oct 2010 04:04:55 +0000 (14:04 +1000)
committerAndrew Gerrand <adg@golang.org>
Fri, 1 Oct 2010 04:04:55 +0000 (14:04 +1000)
This crops up in a lot of places.
It's just a one-liner, but doesn't add any dependancies.
Seems worth it.

R=r, r2
CC=golang-dev
https://golang.org/cl/2344041

src/pkg/fmt/print.go

index 8fcde73fe21ad075411b673ad839527edb9f4b74..0f3dd44bf0642074b724570fce0bdf0b41103b88 100644 (file)
@@ -159,6 +159,12 @@ func Sprintf(format string, a ...interface{}) string {
        return s
 }
 
+// Errorf formats according to a format specifier and returns the string 
+// converted to an os.ErrorString, which satisfies the os.Error interface.
+func Errorf(format string, a ...interface{}) os.Error {
+       return os.ErrorString(Sprintf(format, a...))
+}
+
 // These routines do not take a format string
 
 // Fprint formats using the default formats for its operands and writes to w.