From 2b9b8d66cccc03da6fae5d87e1026d24301203f3 Mon Sep 17 00:00:00 2001 From: James Coleman Date: Mon, 11 Apr 2016 23:17:07 -0500 Subject: [PATCH] Learned of fmt.Errorf. Why didn't I know of this? --- mpvNowPlaying.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/mpvNowPlaying.go b/mpvNowPlaying.go index 4238b5c..5707a92 100644 --- a/mpvNowPlaying.go +++ b/mpvNowPlaying.go @@ -29,20 +29,6 @@ func MPVSocket() string { return path.Join(usr.HomeDir, ".config/mpv/mpv.sock") } -type MPVError struct { - s string -} - -func (e *MPVError) Error() string { - return e.s -} - -func newMPVError(s string) *MPVError { - err := new(MPVError) - err.s = s - return err -} - type FloatResult struct { Data float64 `json:"data"` Error string `json:"error"` @@ -62,7 +48,7 @@ func GetPropertyFloat(conn net.Conn, propertyName string) (float64, error) { log.Fatal("Config file error: ", err) } if floatResult.Error != "success" { - return -1, newMPVError(floatResult.Error) + return -1, fmt.Errorf(floatResult.Error) } return floatResult.Data, nil } @@ -86,7 +72,7 @@ func GetPropertyString(conn net.Conn, propertyName string) (string, error) { log.Fatal("Config file error: ", err) } if stringResult.Error != "success" { - return "", newMPVError(stringResult.Error) + return "", fmt.Errorf(stringResult.Error) } return stringResult.Data, nil }