[Groonga-commit] groonga/grnci at 7f09a0d [master] Simplify DB.RubyEval and DB.RubyLoad.

Back to archive index

Susumu Yata null+****@clear*****
Tue Sep 12 16:24:09 JST 2017


Susumu Yata	2017-09-12 16:24:09 +0900 (Tue, 12 Sep 2017)

  New Revision: 7f09a0d5393ce2e86a4607894e7fdacff6286d65
  https://github.com/groonga/grnci/commit/7f09a0d5393ce2e86a4607894e7fdacff6286d65

  Message:
    Simplify DB.RubyEval and DB.RubyLoad.
    
    Ref: #42

  Modified files:
    v2/db.go

  Modified: v2/db.go (+18 -20)
===================================================================
--- v2/db.go    2017-09-12 16:22:08 +0900 (ce12b70)
+++ v2/db.go    2017-09-12 16:24:09 +0900 (655664f)
@@ -1387,59 +1387,57 @@ func (db *DB) RequestCancel(id int) error {
 }
 
 // RubyEval executes ruby_eval.
-func (db *DB) RubyEval(script string) (interface{}, Response, error) {
+func (db *DB) RubyEval(script string) (interface{}, error) {
 	resp, err := db.Invoke("ruby_eval", map[string]interface{}{
 		"script": script,
 	}, 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
 	}
 	type Result struct {
 		Value interface{} `json:"value"`
 	}
 	var result Result
-	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 false, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
+				"error": err.Error(),
+			})
 		}
-		return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
-			"error": err.Error(),
-		})
 	}
-	return result.Value, resp, nil
+	return result.Value, resp.Err()
 }
 
 // RubyLoad executes ruby_load.
-func (db *DB) RubyLoad(path string) (interface{}, Response, error) {
+func (db *DB) RubyLoad(path string) (interface{}, error) {
 	resp, err := db.Invoke("ruby_load", map[string]interface{}{
 		"path": path,
 	}, 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
 	}
 	type Result struct {
 		Value interface{} `json:"value"`
 	}
 	var result Result
-	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 false, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
+				"error": err.Error(),
+			})
 		}
-		return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{
-			"error": err.Error(),
-		})
 	}
-	return result.Value, resp, nil
+	return result.Value, resp.Err()
 }
 
 // DBSchemaPlugin is a part of DBSchema.
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170912/1d908738/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index