✨ improve the functions related to commenting on images
This commit is contained in:
@@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/acmestack/gorm-plus/gplus"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
@@ -61,5 +62,7 @@ func MySQlConnect() *gorm.DB {
|
||||
sqlDB.SetMaxIdleConns(global.CONFIG.MySQL.MaxIdleConnes)
|
||||
sqlDB.SetMaxOpenConns(global.CONFIG.MySQL.MaxOpenConnes)
|
||||
sqlDB.SetConnMaxLifetime(time.Hour * 4) //连接最大复用时间
|
||||
// 初始化gplus
|
||||
gplus.Init(db)
|
||||
return db
|
||||
}
|
||||
|
40
core/mongodb.go
Normal file
40
core/mongodb.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"schisandra-cloud-album/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InitMongoDB initializes the MongoDB connection
|
||||
func InitMongoDB() {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
clientOptions := options.Client().ApplyURI(global.CONFIG.MongoDB.MongoDsn())
|
||||
clientOptions.SetAuth(options.Credential{
|
||||
AuthMechanism: "SCRAM-SHA-256",
|
||||
AuthMechanismProperties: nil,
|
||||
AuthSource: global.CONFIG.MongoDB.AuthSource,
|
||||
Username: global.CONFIG.MongoDB.User,
|
||||
Password: global.CONFIG.MongoDB.Password,
|
||||
PasswordSet: true,
|
||||
})
|
||||
connect, err := mongo.Connect(ctx, clientOptions)
|
||||
if err != nil {
|
||||
global.LOG.Fatalf(err.Error())
|
||||
return
|
||||
}
|
||||
// Check the connection
|
||||
err = connect.Ping(context.TODO(), nil)
|
||||
if err != nil {
|
||||
global.LOG.Fatalf(err.Error())
|
||||
return
|
||||
}
|
||||
global.MongoDB = connect
|
||||
fmt.Println("Connected to MongoDB!")
|
||||
}
|
Reference in New Issue
Block a user