generate facade service
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package dal
|
||||
|
||||
import (
|
||||
"github.com/suyiiyii/hertz101/app/facade/biz/dal/mysql"
|
||||
"github.com/suyiiyii/hertz101/app/facade/biz/dal/redis"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
redis.Init()
|
||||
mysql.Init()
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"github.com/suyiiyii/hertz101/app/facade/conf"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
DB *gorm.DB
|
||||
err error
|
||||
)
|
||||
|
||||
func Init() {
|
||||
DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN),
|
||||
&gorm.Config{
|
||||
PrepareStmt: true,
|
||||
SkipDefaultTransaction: true,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/suyiiyii/hertz101/app/facade/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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user