From 3c1824fc7e82dd172619c06a2189da936c934318 Mon Sep 17 00:00:00 2001 From: Malik Al Date: Fri, 6 Dec 2024 21:19:25 +0700 Subject: [PATCH] fixes --- sing-geoip/main.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sing-geoip/main.go b/sing-geoip/main.go index 0234dbcef..25205a890 100644 --- a/sing-geoip/main.go +++ b/sing-geoip/main.go @@ -39,21 +39,12 @@ func init() { } func fetch(from string) (*github.RepositoryRelease, error) { - fixedRelease := os.Getenv("FIXED_RELEASE") names := strings.SplitN(from, "/", 2) - if fixedRelease != "" { - latestRelease, _, err := githubClient.Repositories.GetReleaseByTag(context.Background(), names[0], names[1], fixedRelease) - if err != nil { - return nil, err - } - return latestRelease, err - } else { - latestRelease, _, err := githubClient.Repositories.GetLatestRelease(context.Background(), names[0], names[1]) - if err != nil { - return nil, err - } - return latestRelease, err + latestRelease, _, err := githubClient.Repositories.GetLatestRelease(context.Background(), names[0], names[1]) + if err != nil { + return nil, err } + return latestRelease, err } func get(downloadURL *string) ([]byte, error) { @@ -91,8 +82,18 @@ func parse(binary []byte) (metadata maxminddb.Metadata, countryMap map[string][] if err != nil { return } - // idk why - code := strings.ToLower(country.RegisteredCountry.IsoCode) + var code string + if country.Country.IsoCode != "" { + code = strings.ToLower(country.Country.IsoCode) + } else if country.RegisteredCountry.IsoCode != "" { + code = strings.ToLower(country.RegisteredCountry.IsoCode) + } else if country.RepresentedCountry.IsoCode != "" { + code = strings.ToLower(country.RepresentedCountry.IsoCode) + } else if country.Continent.Code != "" { + code = strings.ToLower(country.Continent.Code) + } else { + continue + } countryMap[code] = append(countryMap[code], ipNet) } err = networks.Err()