package svc import ( "app-cloudep-tweeting-service/internal/config" model "app-cloudep-tweeting-service/internal/model/mongo" "fmt" vi "code.30cm.net/digimon/library-go/validator" ) type ServiceContext struct { Config config.Config Validate vi.Validate PostModel model.PostModel PostLikeModel model.Post_likesModel } func NewServiceContext(c config.Config) *ServiceContext { baseMongo := MustMongoConnectUrl(c) postCollection := model.Post{} postLikeCollection := model.PostLikes{} return &ServiceContext{ Config: c, Validate: vi.MustValidator(), PostModel: model.NewPostModel(baseMongo, c.Mongo.Database, postCollection.CollectionName(), c.Cache), PostLikeModel: model.NewPost_likesModel(baseMongo, c.Mongo.Database, postLikeCollection.CollectionName()), } } func MustMongoConnectUrl(c config.Config) string { return fmt.Sprintf( "%s://%s:%s", c.Mongo.Schema, c.Mongo.Host, c.Mongo.Port) }