-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.go
49 lines (39 loc) · 1.49 KB
/
domain.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package domain
import (
"fmt"
"github.com/rs/zerolog/log"
"github.com/ssup2-playground/msa-event-market_service-auth/internal/config"
"github.com/ssup2-playground/msa-event-market_service-auth/internal/domain/repo"
"github.com/ssup2-playground/msa-event-market_service-auth/internal/domain/service"
)
type Domain struct {
// Config
Configs *config.Configs
// Service
User service.UserService
Token service.TokenService
}
func New(c *config.Configs) (*Domain, error) {
// Init domain and config
domain := Domain{
Configs: c,
}
// Init repo
txMySQL, primaryMySQL, secondaryMySQL, err := repo.New(c)
if err != nil {
log.Error().Err(err).Msg("Failed to init repo pkg")
return nil, fmt.Errorf("failed to init repo pkg")
}
outboxRepoPrimaryMysql := repo.NewOutboxRepoImp(primaryMySQL)
userInfoRepoPrimaryMysql := repo.NewUserInfoRepoImp(primaryMySQL)
userInfoRepoSecondaryMysql := repo.NewUserInfoRepoImp(secondaryMySQL)
userSecretRepoPrimaryMysql := repo.NewUserSecretRepoImp(primaryMySQL)
userSecretRepoSecondaryMysql := repo.NewUserSecretRepoImp(secondaryMySQL)
// Init services
userService := service.NewUserServiceImp(txMySQL, outboxRepoPrimaryMysql,
userInfoRepoPrimaryMysql, userInfoRepoSecondaryMysql, userSecretRepoPrimaryMysql, userSecretRepoSecondaryMysql)
tokenService := service.NewTokenServiceImp(txMySQL, userInfoRepoSecondaryMysql, userSecretRepoPrimaryMysql, userSecretRepoSecondaryMysql)
domain.User = userService
domain.Token = tokenService
return &domain, nil
}