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

32 lines
685 B
Go

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