app-cloudep-tweeting-service/internal/svc/init_mongo.go

30 lines
683 B
Go
Raw Permalink Normal View History

package svc
import (
"app-cloudep-tweeting-service/internal/config"
model "app-cloudep-tweeting-service/internal/model/mongo"
"fmt"
)
2024-09-03 09:47:34 +00:00
func mustMongoConnectURL(c config.Config) string {
return fmt.Sprintf("%s://%s:%s",
c.Mongo.Schema,
c.Mongo.Host,
c.Mongo.Port,
)
}
// TODO 思考快取做在那邊
func MustPostModel(c config.Config) model.PostModel {
postCollection := model.Post{}
2024-09-03 09:47:34 +00:00
return model.NewPostModel(mustMongoConnectURL(c), c.Mongo.Database, postCollection.CollectionName())
}
func MustCommentModel(c config.Config) model.CommentModel {
m := model.Comment{}
2024-09-03 09:47:34 +00:00
return model.NewCommentModel(mustMongoConnectURL(c), c.Mongo.Database, m.CollectionName())
}