/
service.go
38 lines (33 loc) · 990 Bytes
/
service.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
package facebook
import (
"github.com/RichardKnop/example-api/accounts"
"github.com/RichardKnop/example-api/config"
"github.com/jinzhu/gorm"
)
// Service struct keeps objects to avoid passing them around
type Service struct {
cnf *config.Config
db *gorm.DB
accountsService accounts.ServiceInterface
adapter AdapterInterface
}
// NewService starts a new Service instance
func NewService(cnf *config.Config, db *gorm.DB, accountsService accounts.ServiceInterface, adapter AdapterInterface) *Service {
if adapter == nil {
adapter = NewAdapter(cnf)
}
return &Service{
cnf: cnf,
db: db,
accountsService: accountsService,
adapter: adapter,
}
}
// GetAccountsService returns accounts.Service instance
func (s *Service) GetAccountsService() accounts.ServiceInterface {
return s.accountsService
}
// GetAdapter returns Adapter instance
func (s *Service) GetAdapter() AdapterInterface {
return s.adapter
}