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

54 lines
1.7 KiB
Go
Raw Normal View History

2024-08-28 09:09:01 +00:00
package svc
import (
"app-cloudep-tweeting-service/internal/config"
2024-09-01 14:47:24 +00:00
domainRepo "app-cloudep-tweeting-service/internal/domain/repository"
2024-09-02 13:43:03 +00:00
"app-cloudep-tweeting-service/internal/lib/neo4j"
model "app-cloudep-tweeting-service/internal/model/mongo"
2024-09-01 14:47:24 +00:00
"app-cloudep-tweeting-service/internal/repository"
"github.com/zeromicro/go-zero/core/stores/redis"
vi "code.30cm.net/digimon/library-go/validator"
)
2024-08-28 09:09:01 +00:00
type ServiceContext struct {
2024-09-02 13:43:03 +00:00
Config config.Config
Validate vi.Validate
PostModel model.PostModel
CommentModel model.CommentModel
TimelineRepo domainRepo.TimelineRepository
SocialNetworkRepository domainRepo.SocialNetworkRepository
2024-08-28 09:09:01 +00:00
}
func NewServiceContext(c config.Config) *ServiceContext {
2024-09-01 14:47:24 +00:00
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
if err != nil {
panic(err)
}
2024-09-02 13:43:03 +00:00
neoClient := neo4j.NewNeo4J(&neo4j.Config{
URI: c.Neo4J.URI,
Username: c.Neo4J.Username,
Password: c.Neo4J.Password,
MaxConnectionPoolSize: c.Neo4J.MaxConnectionPoolSize,
MaxConnectionLifetime: c.Neo4J.MaxConnectionLifetime,
ConnectionTimeout: c.Neo4J.ConnectionTimeout,
}, neo4j.WithPerformance(), neo4j.WithLogLevel(c.Neo4J.LogLevel))
2024-08-28 09:09:01 +00:00
return &ServiceContext{
Config: c,
Validate: vi.MustValidator(),
PostModel: MustPostModel(c),
CommentModel: MustCommentModel(c),
2024-09-02 13:43:03 +00:00
TimelineRepo: repository.MustGenerateRepository(repository.TimelineRepositoryParam{
2024-09-01 14:47:24 +00:00
Config: c,
Redis: *newRedis,
}),
2024-09-02 13:43:03 +00:00
SocialNetworkRepository: repository.MustSocialNetworkRepository(repository.SocialNetworkParam{
Config: c,
Neo4jClient: neoClient,
}),
2024-08-28 09:09:01 +00:00
}
}