-
Notifications
You must be signed in to change notification settings - Fork 13
/
google_analytics.go
57 lines (45 loc) · 1.37 KB
/
google_analytics.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
50
51
52
53
54
55
56
57
package googleanalytics
import (
"os"
"github.com/coretrix/hitrix/service/component/config"
errorlogger "github.com/coretrix/hitrix/service/component/error_logger"
)
type NewProviderFunc func(configFolder string, configService config.IConfig, errorLogger errorlogger.ErrorLogger) (IProvider, error)
type IAPIManager interface {
GetProvider(name Provider) IProvider
}
type APIManager struct {
Providers map[string]IProvider
ProvidersByIndex map[int]IProvider
}
func NewAPIManager(
localConfigFolder string,
configService config.IConfig,
errorLogger errorlogger.ErrorLogger,
newProviderFunctions ...NewProviderFunc,
) (IAPIManager, error) {
providers := map[string]IProvider{}
providersByIndex := map[int]IProvider{}
var configFolder string
appFolder, hasConfigFolder := os.LookupEnv("APP_FOLDER")
if !hasConfigFolder {
configFolder = localConfigFolder
} else {
configFolder = appFolder + "/config"
}
for i, newProviderFunc := range newProviderFunctions {
provider, err := newProviderFunc(configFolder, configService, errorLogger)
if err != nil {
return nil, err
}
providers[provider.GetName().String()] = provider
providersByIndex[i] = provider
}
return &APIManager{
Providers: providers,
ProvidersByIndex: providersByIndex,
}, nil
}
func (a *APIManager) GetProvider(name Provider) IProvider {
return a.Providers[name.String()]
}