-
Notifications
You must be signed in to change notification settings - Fork 14
/
dynamic_link.go
127 lines (107 loc) · 4.46 KB
/
dynamic_link.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package registry
import (
"errors"
"fmt"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/dynamic_link/firebase"
"github.com/sarulabs/di"
)
func ServiceDefinitionDynamicLink() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.DynamicLinkService,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(config.IConfig)
apiKey, ok := configService.String("firebase.api_key")
if !ok {
return nil, errors.New("missing firebase.api_key key")
}
domainUriPrefix, ok := configService.String("firebase.dynamic_link_info.domain_uri_prefix")
if !ok {
return nil, errors.New("missing firebase.dynamic_link_info.domain_uri_prefix key")
}
link, ok := configService.String("firebase.dynamic_link_info.link")
if !ok {
return nil, errors.New("missing firebase.dynamic_link_info.link key")
}
generator := &firebase.Generator{
ApiKey: apiKey,
DynamicLinkInfo: &firebase.DynamicLinkInfo{
DomainUriPrefix: domainUriPrefix,
Link: link,
},
}
androidInfoMap, ok := configService.StringMap("firebase.dynamic_link_info.android_info")
if ok {
generator.DynamicLinkInfo.AndroidInfo = &firebase.AndroidInfo{
AndroidPackageName: androidInfoMap["package_name"],
AndroidFallbackLink: androidInfoMap["fallback_link"],
AndroidMinPackageVersionCode: androidInfoMap["min_package_version_code"],
}
}
iosInfoMap, ok := configService.StringMap("firebase.dynamic_link_info.ios_info")
if ok {
generator.DynamicLinkInfo.IosInfo = &firebase.IosInfo{
IosBundleID: iosInfoMap["bundle_id"],
IosFallbackLink: iosInfoMap["fallback_link"],
IosCustomScheme: iosInfoMap["custom_scheme"],
IosIpadFallbackLink: iosInfoMap["ipad_fallback_link"],
IosIpadBundleID: iosInfoMap["ipad_bundle_id"],
IosAppStoreID: iosInfoMap["app_store_id"],
}
}
enableForcedRedirect, ok := configService.Bool("firebase.dynamic_link_info.navigation_info.enable_forced_redirect")
if ok {
generator.DynamicLinkInfo.NavigationInfo = &firebase.NavigationInfo{
EnableForcedRedirect: enableForcedRedirect,
}
}
googlePlayAnalyticsMap, ok := configService.StringMap("firebase.dynamic_link_info.analytics_info.google_play_analytics")
if ok {
if generator.DynamicLinkInfo.AnalyticsInfo == nil {
generator.DynamicLinkInfo.AnalyticsInfo = &firebase.AnalyticsInfo{}
}
generator.DynamicLinkInfo.AnalyticsInfo.GooglePlayAnalytics = &firebase.GooglePlayAnalytics{
UtmSource: googlePlayAnalyticsMap["utm_source"],
UtmMedium: googlePlayAnalyticsMap["utm_medium"],
UtmCampaign: googlePlayAnalyticsMap["utm_campaign"],
UtmTerm: googlePlayAnalyticsMap["utm_term"],
UtmContent: googlePlayAnalyticsMap["utm_content"],
GclID: googlePlayAnalyticsMap["gcl_id"],
}
}
itunesConnectAnalyticsMap, ok := configService.StringMap("firebase.dynamic_link_info.analytics_info.itunes_connect_analytics")
if ok {
if generator.DynamicLinkInfo.AnalyticsInfo == nil {
generator.DynamicLinkInfo.AnalyticsInfo = &firebase.AnalyticsInfo{}
}
generator.DynamicLinkInfo.AnalyticsInfo.ItunesConnectAnalytics = &firebase.ItunesConnectAnalytics{
At: itunesConnectAnalyticsMap["at"],
Ct: itunesConnectAnalyticsMap["ct"],
Mt: itunesConnectAnalyticsMap["mt"],
Pt: itunesConnectAnalyticsMap["pt"],
}
}
socialMetTagInfoMap, ok := configService.StringMap("firebase.dynamic_link_info.social_meta_tag_info")
if ok {
generator.DynamicLinkInfo.SocialMetaTagInfo = &firebase.SocialMetaTagInfo{
SocialTitle: socialMetTagInfoMap["social_title"],
SocialDescription: socialMetTagInfoMap["social_description"],
SocialImageLink: socialMetTagInfoMap["social_image_link"],
}
}
suffixOption, ok := configService.String("firebase.suffix.option")
if ok {
if _, ok := firebase.ValidSuffixOptionsMap[suffixOption]; !ok {
availableSuffixOptions := make([]string, 0)
for k := range firebase.ValidSuffixOptionsMap {
availableSuffixOptions = append(availableSuffixOptions, k)
}
panic(fmt.Sprintf("invalid firebase.suffix.option value, please provide one of following: %v", availableSuffixOptions))
}
generator.Suffix = &firebase.Suffix{Option: suffixOption}
}
return generator, nil
},
}
}