cephfs admin: make a common func for unmarshaling json responses
@@ -79,14 +79,8 @@ type listNamedResult struct {
}
func parseListNames(res []byte, status string, err error) ([]string, error) {
- if err != nil {
- return nil, err
- }
- if status != "" {
- return nil, fmt.Errorf("error status: %s", status)
- }
var r []listNamedResult
- if err := json.Unmarshal(res, &r); err != nil {
+ if err := unmarshalResponseJSON(res, status, err, &r); err != nil {
return nil, err
}
vl := make([]string, len(r))
@@ -111,6 +105,16 @@ func checkEmptyResponseExpected(res []byte, status string, err error) error {
return nil
}
+func unmarshalResponseJSON(res []byte, status string, err error, v interface{}) error {
+ if err != nil {
+ return err
+ }
+ if status != "" {
+ return fmt.Errorf("error status: %s", status)
+ }
+ return json.Unmarshal(res, v)
+}
+
// modeString converts a unix-style mode value to a string-ified version in an
// octal representation (e.g. "777", "700", etc). This format is expected by
// some of the ceph JSON command inputs.
