@@ -159,24 +159,24 @@ 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 != "" {
163
- log .Info ("GeoIP feature is enable" )
162
+ var fetcher geolite2.GeoliteFetcher
164
163
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 ))
170
- }
171
- } else if cfg .GeoipMaxmindLicense != "" {
172
- log .Info ("GeoIP feature is enable" )
164
+ switch {
165
+ case cfg .GeoipMirror != "" :
166
+ fetcher = geolite2 .FetchFromMirror (cfg .GeoipMirror )
167
+ case cfg .GeoipMaxmindLicense != "" :
168
+ fetcher = geolite2 .FetchFromLicenseKey (cfg .GeoipMaxmindLicense )
169
+ }
173
170
174
- locator , err := geolite2 .NewLocator (ctx , geolite2 .FetchFromLicenseKey (cfg .GeoipMaxmindLicense ))
171
+ if fetcher != nil {
172
+ locator , err := geolite2 .NewLocator (ctx , fetcher )
175
173
if err != nil {
176
174
log .WithError (err ).Fatal ("Failed to init GeoIP" )
177
- } else {
178
- servicesOptions = append (servicesOptions , services .WithLocator (locator ))
179
175
}
176
+
177
+ servicesOptions = append (servicesOptions , services .WithLocator (locator ))
178
+
179
+ log .Info ("GeoIP feature is enable" )
180
180
}
181
181
182
182
service := services .NewService (store , nil , nil , cache , apiClient , servicesOptions ... )
0 commit comments