Skip to content

Commit

Permalink
refactor(api): simplifying geoip initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
henrybarreto authored and gustavosbarreto committed Jan 2, 2025
1 parent 2964ca4 commit 3eb94cc
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down

0 comments on commit 3eb94cc

Please sign in to comment.