Susumu Yata
null+****@clear*****
Tue Sep 12 16:22:08 JST 2017
Susumu Yata 2017-09-12 16:22:08 +0900 (Tue, 12 Sep 2017) New Revision: ce7ef735112c8bb07a54bac27856ab44325f23c2 https://github.com/groonga/grnci/commit/ce7ef735112c8bb07a54bac27856ab44325f23c2 Message: Simplify DB.ObjectList. Ref: #42 Modified files: v2/db.go Modified: v2/db.go (+12 -10) =================================================================== --- v2/db.go 2017-09-12 16:18:59 +0900 (60a3e0e) +++ v2/db.go 2017-09-12 16:22:08 +0900 (ce12b70) @@ -1226,26 +1226,28 @@ type DBObject struct { } // ObjectList executes object_list. -func (db *DB) ObjectList() (map[string]*DBObject, Response, error) { +func (db *DB) ObjectList() (map[string]*DBObject, error) { resp, err := db.Invoke("object_list", nil, nil) if err != nil { - return nil, nil, err + return nil, err } defer resp.Close() jsonData, err := ioutil.ReadAll(resp) if err != nil { - return nil, resp, err + return nil, err } var result map[string]*DBObject - if err := json.Unmarshal(jsonData, &result); err != nil { - if resp.Err() != nil { - return nil, resp, nil + if len(jsonData) != 0 { + if err := json.Unmarshal(jsonData, &result); err != nil { + return nil, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + "error": err.Error(), + }) } - return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ - "error": err.Error(), - }) } - return result, resp, nil + if result == nil && resp.Err() == nil { + result = make(map[string]*DBObject) + } + return result, resp.Err() } // ObjectRemove executes object_remove. -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170912/20b6d9fa/attachment-0001.htm