mirror of
https://github.com/therootcompany/golib.git
synced 2026-04-24 20:58:00 +00:00
- httpcache.Cacher loses Transform (always atomic copy to Path); adds BasicAuth and Bearer helpers for Authorization header values. - geoip.Open now reads <dir>/GeoLite2-City.tar.gz and GeoLite2-ASN.tar.gz directly: extracts the .mmdb entry in memory and opens via geoip2.FromBytes. No .mmdb files written to disk. - geoip.Downloader/New/NewCacher/Fetch/ExtractMMDB removed — geoip is purely read/lookup; fetching is each caller's concern. - cmd/check-ip/main.go is a single main() again: blocklists via gitshallow+dataset, geoip via two httpcache.Cachers (if GeoIP.conf present) + geoip.Open. No geo refresh loop, no dataset.Group for geo. - cmd/geoip-update and the integration test construct httpcache.Cachers directly against geoip.DownloadBase + edition IDs, writing .tar.gz.
37 lines
1004 B
Go
37 lines
1004 B
Go
package geoip
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
const (
|
|
CityEdition = "GeoLite2-City"
|
|
ASNEdition = "GeoLite2-ASN"
|
|
CountryEdition = "GeoLite2-Country"
|
|
|
|
// DownloadBase is the MaxMind databases download endpoint. Full URL:
|
|
// <DownloadBase>/<edition>/download?suffix=tar.gz
|
|
DownloadBase = "https://download.maxmind.com/geoip/databases"
|
|
)
|
|
|
|
// DefaultConfPaths returns the standard locations where GeoIP.conf is looked
|
|
// up: ./GeoIP.conf, then ~/.config/maxmind/GeoIP.conf.
|
|
func DefaultConfPaths() []string {
|
|
paths := []string{"GeoIP.conf"}
|
|
if home, err := os.UserHomeDir(); err == nil {
|
|
paths = append(paths, filepath.Join(home, ".config", "maxmind", "GeoIP.conf"))
|
|
}
|
|
return paths
|
|
}
|
|
|
|
// DefaultCacheDir returns the OS cache directory for MaxMind databases,
|
|
// e.g. ~/.cache/maxmind on Linux or ~/Library/Caches/maxmind on macOS.
|
|
func DefaultCacheDir() (string, error) {
|
|
base, err := os.UserCacheDir()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.Join(base, "maxmind"), nil
|
|
}
|