Skip to content

Commit

Permalink
refactor(main.go): 移动记录集合获取逻辑到main函数
Browse files Browse the repository at this point in the history
  • Loading branch information
imshuai committed Dec 11, 2024
1 parent ffd9e09 commit b69b9fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 0 additions & 4 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func loadConfig(c *cli.Context) error {
if err != nil {
return errors.New("open database error: " + err.Error())
}
config.records, err = GetRecordCollection()
if err != nil {
return errors.New("get record collection error: " + err.Error())
}
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -226,6 +227,10 @@ func main() {
logger.Debugf("[MAIN]: update mode: %s", mode)
config.isIncrementalUpdate = !c.Bool("no-incremental-update") //是否使用增量更新
logger.Debugf("[MAIN]: incremental update: %t", config.isIncrementalUpdate)
config.records, err = GetRecordCollection()
if err != nil {
return errors.New("get record collection error: " + err.Error())
}
localStrms := make(map[string]*Strm, 0)
remoteStrms := make(map[string]*Strm, 0)
addStrms := make([]*Strm, 0)
Expand Down
3 changes: 3 additions & 0 deletions strm.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func GetRecordCollection() (map[string]int, error) {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("strm"))
byts := b.Get([]byte("records"))
if byts == nil {
return fmt.Errorf("records not found, must use update-database first")
}
return json.Unmarshal(byts, &records)
})
if err != nil {
Expand Down

0 comments on commit b69b9fd

Please sign in to comment.