-
Notifications
You must be signed in to change notification settings - Fork 1
/
factory.go
36 lines (31 loc) · 813 Bytes
/
factory.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
package infrastructure
import (
"log"
"github.com/akornatskyy/sample-blog-api-go/membership/domain"
"github.com/akornatskyy/sample-blog-api-go/membership/domain/user"
"github.com/akornatskyy/sample-blog-api-go/membership/infrastructure/mock"
"github.com/akornatskyy/sample-blog-api-go/membership/infrastructure/sql"
"github.com/akornatskyy/sample-blog-api-go/shared/config"
)
type (
factory struct {
user user.Repository
}
)
func NewFactory(c *config.Config) domain.Factory {
switch c.Strategy {
case config.StrategySQL:
return &factory{
user: sql.NewUserRepository(c.DB),
}
case config.StrategyMock:
return &factory{
user: mock.NewUserRepository(),
}
}
log.Fatal("unknown repository strategy")
return nil
}
func (f *factory) UserRepository() user.Repository {
return f.user
}