auth service

This commit is contained in:
2025-01-20 16:22:41 +08:00
parent 76d3d6f20a
commit bda2501bae
40 changed files with 3340 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
package dal
import (
"github.com/suyiiyii/hertz101/app/auth/biz/dal/mysql"
)
func Init() {
//redis.Init()
mysql.Init()
}
+33
View File
@@ -0,0 +1,33 @@
package mysql
import (
"fmt"
"github.com/joho/godotenv"
"github.com/suyiiyii/hertz101/app/auth/conf"
"os"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var (
DB *gorm.DB
err error
)
func Init() {
err := godotenv.Load()
if err != nil {
panic(err)
}
dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"), os.Getenv("MYSQL_PORT"))
DB, err = gorm.Open(mysql.Open(dsn),
&gorm.Config{
PrepareStmt: true,
SkipDefaultTransaction: true,
},
)
if err != nil {
panic(err)
}
}
+24
View File
@@ -0,0 +1,24 @@
package redis
import (
"context"
"github.com/redis/go-redis/v9"
"github.com/suyiiyii/hertz101/app/auth/conf"
)
var (
RedisClient *redis.Client
)
func Init() {
RedisClient = redis.NewClient(&redis.Options{
Addr: conf.GetConf().Redis.Address,
Username: conf.GetConf().Redis.Username,
Password: conf.GetConf().Redis.Password,
DB: conf.GetConf().Redis.DB,
})
if err := RedisClient.Ping(context.Background()).Err(); err != nil {
panic(err)
}
}