mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +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
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -18,8 +19,8 @@ var EnableCacheDB bool
|
|||||||
|
|
||||||
// Media Cache DBs
|
// Media Cache DBs
|
||||||
var (
|
var (
|
||||||
Image *Cache
|
Image Cache
|
||||||
Video *Cache
|
Video Cache
|
||||||
// todo: Voice?
|
// todo: Voice?
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,29 +62,24 @@ func Init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to read cache config: %v", err)
|
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) {
|
var open = func(typ string, cache *Cache) {
|
||||||
if global.PathExists(conf[typ]) {
|
file := conf[typ]
|
||||||
db, err := btree.Open(conf[typ])
|
if file == "" {
|
||||||
|
file = fmt.Sprintf("data/%s.db", typ)
|
||||||
|
}
|
||||||
|
if global.PathExists(file) {
|
||||||
|
db, err := btree.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("open %s cache failed: %v", typ, err)
|
log.Fatalf("open %s cache failed: %v", typ, err)
|
||||||
}
|
}
|
||||||
*cache = &Cache{db: db}
|
cache.db = db
|
||||||
} else {
|
} else {
|
||||||
db, err := btree.Create(conf[typ])
|
db, err := btree.Create(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("create %s cache failed: %v", typ, err)
|
log.Fatalf("create %s cache failed: %v", typ, err)
|
||||||
}
|
}
|
||||||
*cache = &Cache{db: db}
|
cache.db = db
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
open("image", &Image)
|
open("image", &Image)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user