From 0b106d8ef573b36c3e2f78282e4d3fda7ec173d3 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Tue, 14 Mar 2023 20:56:11 +0800 Subject: [PATCH] db/sqlite: use ParseDuration --- db/sqlite3/sqlite3.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/db/sqlite3/sqlite3.go b/db/sqlite3/sqlite3.go index 7db6feb..a4f1256 100644 --- a/db/sqlite3/sqlite3.go +++ b/db/sqlite3/sqlite3.go @@ -11,6 +11,7 @@ import ( sql "github.com/FloatTech/sqlite" "github.com/pkg/errors" + log "github.com/sirupsen/logrus" "gopkg.in/yaml.v3" "github.com/Mrs4s/MiraiGo/binary" @@ -27,8 +28,8 @@ type database struct { // config mongodb 相关配置 type config struct { - Enable bool `yaml:"enable"` - CacheTTL time.Duration `yaml:"cachettl"` + Enable bool `yaml:"enable"` + CacheTTL string `yaml:"cachettl"` } func init() { @@ -39,7 +40,11 @@ func init() { if !conf.Enable { 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} }) }