-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.go
46 lines (40 loc) · 1.08 KB
/
container.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
package container
import (
"github.com/raulinoneto/golang-ifood-sdk/authentication"
"github.com/raulinoneto/golang-ifood-sdk/httpadapter"
"github.com/raulinoneto/golang-ifood-sdk/mocks"
"net/http"
"time"
)
type container struct {
env int
timeout time.Duration
httpadapter HttpAdapter
authService authentication.Service
}
func New(env int, timeout time.Duration) *container {
return &container{env: env,timeout: timeout}
}
func (c *container)GetHttpAdapter() HttpAdapter{
if c.httpadapter != nil {
return c.httpadapter
}
client := &http.Client{
Timeout: c.timeout,
}
switch c.env {
case EnvDevelopment:
c.httpadapter = httpadapter.New(new(mocks.HttpClientMock), "")
case EnvProduction:
c.httpadapter = httpadapter.New(client, urlProduction)
case EnvSandBox:
c.httpadapter = httpadapter.New(client, urlSandbox)
}
return c.httpadapter
}
func (c container) GetAuthenticationService(clientId, clientSecret string) authentication.Service{
if c.authService == nil {
c.authService = authentication.New(c.GetHttpAdapter(), clientId, clientSecret)
}
return c.authService
}