/
service.go
41 lines (36 loc) · 1.1 KB
/
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
39
40
41
package accounts
import (
"github.com/RichardKnop/example-api/config"
"github.com/RichardKnop/example-api/email"
"github.com/RichardKnop/example-api/oauth"
"github.com/jinzhu/gorm"
)
// Service struct keeps config and db objects to avoid passing them around
type Service struct {
cnf *config.Config
db *gorm.DB
oauthService oauth.ServiceInterface
emailService email.ServiceInterface
emailFactory EmailFactoryInterface
}
// NewService starts a new Service instance
func NewService(cnf *config.Config, db *gorm.DB, oauthService oauth.ServiceInterface, emailService email.ServiceInterface, emailFactory EmailFactoryInterface) *Service {
if emailFactory == nil {
emailFactory = NewEmailFactory(cnf)
}
return &Service{
cnf: cnf,
db: db,
oauthService: oauthService,
emailService: emailService,
emailFactory: emailFactory,
}
}
// GetConfig returns config.Config instance
func (s *Service) GetConfig() *config.Config {
return s.cnf
}
// GetOauthService returns oauth.Service instance
func (s *Service) GetOauthService() oauth.ServiceInterface {
return s.oauthService
}