-
Notifications
You must be signed in to change notification settings - Fork 14
/
google_analytics.go
50 lines (39 loc) · 1.2 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
package googleanalytics
import (
"os"
"github.com/coretrix/hitrix/service/component/config"
)
type NewProviderFunc func(configFolder string, configService config.IConfig) (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, 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)
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()]
}