diff --git a/api/server.go b/api/server.go index 8ac546560f0..cbaa4c6169f 100644 --- a/api/server.go +++ b/api/server.go @@ -159,24 +159,24 @@ func startServer(ctx context.Context, cfg *config, store store.Store, cache stor servicesOptions := []services.Option{} - if cfg.GeoipMirror != "" { - log.Info("GeoIP feature is enable") + var fetcher geolite2.GeoliteFetcher - locator, err := geolite2.NewLocator(ctx, geolite2.FetchFromMirror(cfg.GeoipMirror)) - if err != nil { - log.WithError(err).Fatal("Failed to init GeoIP") - } else { - servicesOptions = append(servicesOptions, services.WithLocator(locator)) - } - } else if cfg.GeoipMaxmindLicense != "" { - log.Info("GeoIP feature is enable") + switch { + case cfg.GeoipMirror != "": + fetcher = geolite2.FetchFromMirror(cfg.GeoipMirror) + case cfg.GeoipMaxmindLicense != "": + fetcher = geolite2.FetchFromLicenseKey(cfg.GeoipMaxmindLicense) + } - locator, err := geolite2.NewLocator(ctx, geolite2.FetchFromLicenseKey(cfg.GeoipMaxmindLicense)) + if fetcher != nil { + locator, err := geolite2.NewLocator(ctx, fetcher) if err != nil { log.WithError(err).Fatal("Failed to init GeoIP") - } else { - servicesOptions = append(servicesOptions, services.WithLocator(locator)) } + + servicesOptions = append(servicesOptions, services.WithLocator(locator)) + + log.Info("GeoIP feature is enable") } service := services.NewService(store, nil, nil, cache, apiClient, servicesOptions...)