From 0d1558fa7cabaf35f7da9adf0f5a5804c9404f2a Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 01 十二月 2021 14:42:59 +0800
Subject: [PATCH] foreach 添加error返回

---
 api.go        |    4 ++--
 bolt_store.go |   10 ++++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/api.go b/api.go
index 7af4fc6..6da586f 100644
--- a/api.go
+++ b/api.go
@@ -52,8 +52,8 @@
 }
 
 // 閬嶅巻鏁版嵁, 杈撳嚭鍘熷鏁版嵁
-func (ls *LogStore) ForEach(f func(v *LogCon) error) {
-	ls.store.ForEach(f)
+func (ls *LogStore) ForEach(f func(v *LogCon) error) error {
+	return ls.store.ForEach(f)
 }
 
 func (ls *LogStore) Size() int {
diff --git a/bolt_store.go b/bolt_store.go
index 505e2ea..368467a 100644
--- a/bolt_store.go
+++ b/bolt_store.go
@@ -242,10 +242,10 @@
 	return tx.Commit()
 }
 
-func (b *BoltStore) ForEach(f func(lc *LogCon) error) {
+func (b *BoltStore) ForEach(f func(lc *LogCon) error) error {
 	tx, err := b.conn.Begin(true)
 	if err != nil {
-		return
+		return err
 	}
 	defer tx.Rollback()
 
@@ -256,13 +256,13 @@
 		cLog := &confLog{}
 		err := b.GetConfLog(start, cLog)
 		if err != nil {
-			return
+			return err
 		}
 
 		bucketName := cLog.BucketName
 		bucket := tx.Bucket([]byte(bucketName))
 		if bucket == nil {
-			return
+			return err
 		}
 
 		bucket.ForEach(func(k, v []byte) error {
@@ -275,6 +275,8 @@
 			return err
 		})
 	}
+
+	return nil
 }
 
 func (b *BoltStore) Delete(lc *LogCon) error {

--
Gitblit v1.8.0