Add a cache layer in auth to speed up auth

This commit is contained in:
2024-03-23 00:28:27 +08:00
parent 211959167a
commit b69ac44885
11 changed files with 202 additions and 69 deletions

View File

@ -4,6 +4,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/samber/lo"
"github.com/spf13/viper"
"go.etcd.io/bbolt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
@ -12,7 +13,7 @@ import (
var C *gorm.DB
func NewSource() error {
func NewGorm() error {
var err error
dialector := postgres.Open(viper.GetString("database.dsn"))
@ -21,8 +22,19 @@ func NewSource() error {
}, Logger: logger.New(&log.Logger, logger.Config{
Colorful: true,
IgnoreRecordNotFoundError: true,
LogLevel: lo.Ternary(viper.GetBool("debug"), logger.Info, logger.Silent),
LogLevel: lo.Ternary(viper.GetBool("debug.database"), logger.Info, logger.Silent),
})})
return err
}
var B *bbolt.DB
func NewBolt() error {
var err error
dsn := viper.GetString("database.bolt")
B, err = bbolt.Open(dsn, 0600, nil)
return err
}