mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +08:00
clean: clean cache.Init
This commit is contained in:
parent
41e33fdb3d
commit
cd5c6c6a72
30
internal/cache/cache.go
vendored
30
internal/cache/cache.go
vendored
@ -2,6 +2,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -18,8 +19,8 @@ var EnableCacheDB bool
|
||||
|
||||
// Media Cache DBs
|
||||
var (
|
||||
Image *Cache
|
||||
Video *Cache
|
||||
Image Cache
|
||||
Video Cache
|
||||
// todo: Voice?
|
||||
)
|
||||
|
||||
@ -61,29 +62,24 @@ func Init() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read cache config: %v", err)
|
||||
}
|
||||
if conf == nil {
|
||||
conf = make(map[string]string)
|
||||
}
|
||||
if conf["image"] == "" {
|
||||
conf["image"] = "data/image.db"
|
||||
}
|
||||
if conf["video"] == "" {
|
||||
conf["video"] = "data/video.db"
|
||||
}
|
||||
|
||||
var open = func(typ string, cache **Cache) {
|
||||
if global.PathExists(conf[typ]) {
|
||||
db, err := btree.Open(conf[typ])
|
||||
var open = func(typ string, cache *Cache) {
|
||||
file := conf[typ]
|
||||
if file == "" {
|
||||
file = fmt.Sprintf("data/%s.db", typ)
|
||||
}
|
||||
if global.PathExists(file) {
|
||||
db, err := btree.Open(file)
|
||||
if err != nil {
|
||||
log.Fatalf("open %s cache failed: %v", typ, err)
|
||||
}
|
||||
*cache = &Cache{db: db}
|
||||
cache.db = db
|
||||
} else {
|
||||
db, err := btree.Create(conf[typ])
|
||||
db, err := btree.Create(file)
|
||||
if err != nil {
|
||||
log.Fatalf("create %s cache failed: %v", typ, err)
|
||||
}
|
||||
*cache = &Cache{db: db}
|
||||
cache.db = db
|
||||
}
|
||||
}
|
||||
open("image", &Image)
|
||||
|
Loading…
x
Reference in New Issue
Block a user