1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 11:07:39 +08:00

db/sqlite: use ParseDuration

This commit is contained in:
wdvxdr 2023-03-14 20:56:11 +08:00
parent 40e4f40525
commit 0b106d8ef5

View File

@ -11,6 +11,7 @@ import (
sql "github.com/FloatTech/sqlite" sql "github.com/FloatTech/sqlite"
"github.com/pkg/errors" "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/binary"
@ -27,8 +28,8 @@ type database struct {
// config mongodb 相关配置 // config mongodb 相关配置
type config struct { type config struct {
Enable bool `yaml:"enable"` Enable bool `yaml:"enable"`
CacheTTL time.Duration `yaml:"cachettl"` CacheTTL string `yaml:"cachettl"`
} }
func init() { func init() {
@ -39,7 +40,11 @@ func init() {
if !conf.Enable { if !conf.Enable {
return nil return nil
} }
return &database{db: new(sql.Sqlite), ttl: conf.CacheTTL * time.Millisecond} duration, err := time.ParseDuration(conf.CacheTTL)
if err != nil {
log.Fatalf("illegal ttl config: %v", err)
}
return &database{db: new(sql.Sqlite), ttl: duration}
}) })
} }