feat: user jwt login
This commit is contained in:
39
bootstrap/db.go
Normal file
39
bootstrap/db.go
Normal file
@ -0,0 +1,39 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/cmd/args"
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/store"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
"gorm.io/gorm/schema"
|
||||
stdlog "log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InitDB() {
|
||||
newLogger := logger.New(
|
||||
stdlog.New(log.StandardLogger().Out, "\r\n", stdlog.LstdFlags),
|
||||
logger.Config{
|
||||
SlowThreshold: time.Second,
|
||||
LogLevel: logger.Silent,
|
||||
IgnoreRecordNotFoundError: true,
|
||||
Colorful: true,
|
||||
},
|
||||
)
|
||||
gormConfig := &gorm.Config{
|
||||
NamingStrategy: schema.NamingStrategy{
|
||||
TablePrefix: conf.Conf.Database.TablePrefix,
|
||||
},
|
||||
Logger: newLogger,
|
||||
}
|
||||
if args.Dev {
|
||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), gormConfig)
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
store.Init(db)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user