@@ -159,24 +159,29 @@ func startServer(ctx context.Context, cfg *config, store store.Store, cache stor
159
159
160
160
servicesOptions := []services.Option {}
161
161
162
- if cfg .GeoipMirror != "" {
162
+ if cfg .GeoipMirror != "" || cfg . GeoipMaxmindLicense != "" {
163
163
log .Info ("GeoIP feature is enable" )
164
164
165
- locator , err := geolite2 .NewLocator (ctx , geolite2 .FetchFromMirror (cfg .GeoipMirror ))
166
- if err != nil {
167
- log .WithError (err ).Fatal ("Failed to init GeoIP" )
168
- } else {
169
- servicesOptions = append (servicesOptions , services .WithLocator (locator ))
165
+ var fetcher geolite2.GeoliteFetcher
166
+
167
+ switch {
168
+ case cfg .GeoipMirror != "" :
169
+ fetcher = geolite2 .FetchFromMirror (cfg .GeoipMirror )
170
+ case cfg .GeoipMaxmindLicense != "" :
171
+ fetcher = geolite2 .FetchFromLicenseKey (cfg .GeoipMaxmindLicense )
172
+ default :
173
+ log .WithError (err ).Fatal ("Failed to init GeoIP because no valid value was set" )
170
174
}
171
- } else if cfg .GeoipMaxmindLicense != "" {
172
- log .Info ("GeoIP feature is enable" )
173
175
174
- locator , err := geolite2 .NewLocator (ctx , geolite2 .FetchFromLicenseKey (cfg .GeoipMaxmindLicense ))
176
+ locator , err := geolite2 .NewLocator (ctx , fetcher )
177
+
175
178
if err != nil {
176
179
log .WithError (err ).Fatal ("Failed to init GeoIP" )
177
180
} else {
178
181
servicesOptions = append (servicesOptions , services .WithLocator (locator ))
179
182
}
183
+
184
+ log .Info ("GeoIP feature is enable" )
180
185
}
181
186
182
187
service := services .NewService (store , nil , nil , cache , apiClient , servicesOptions ... )
0 commit comments