Learned of fmt.Errorf. Why didn't I know of this?

This commit is contained in:
James Coleman 2016-04-11 23:17:07 -05:00
parent b93948e250
commit 2b9b8d66cc

View File

@ -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
}