add mongodb/jwt

This commit is contained in:
landaiqing
2024-11-13 13:37:47 +08:00
parent ae743ba8a6
commit c95d5fc041
85 changed files with 3370 additions and 239 deletions

View File

@@ -0,0 +1,13 @@
package collection
import (
"github.com/chenmingyong0423/go-mongox/v2"
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
)
// MustNewCollection creates a new Collection instance with the given name.
func MustNewCollection[T any](svcCtx *svc.ServiceContext, collectionName string) *mongox.Collection[T] {
collection := svcCtx.MongoClient.Collection(collectionName)
return mongox.NewCollection[T](collection)
}

View File

@@ -0,0 +1,28 @@
package mongodb
import (
"context"
"log"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
)
// NewMongoDB initializes the MongoDB connection and returns the database object
func NewMongoDB(uri string, username string, password string, authSource string, database string) *mongo.Database {
client, err := mongo.Connect(options.Client().ApplyURI(uri).SetAuth(options.Credential{
Username: username,
Password: password,
AuthSource: authSource,
}))
if err != nil {
log.Panic(err)
}
err = client.Ping(context.Background(), readpref.Primary())
if err != nil {
log.Panic(err)
}
db := client.Database(database)
return db
}

View File

@@ -0,0 +1,11 @@
package model
import "github.com/chenmingyong0423/go-mongox/v2"
type CommentImage struct {
mongox.Model `bson:",inline"`
TopicID string `bson:"topic_id"`
CommentID string `bson:"comment_id"`
UserID string `bson:"user_id"`
Images []string `bson:"images"`
}