fix: GeoIP opcional, no paniquea si falta GeoLite2-City.mmdb
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e28e2823dc
commit
d66fe95514
+3
-3
@@ -36,11 +36,11 @@ func LoadBuiltInMiddlewares(app *config.AppConfig) {
|
|||||||
|
|
||||||
|
|
||||||
func Location(c *fiber.Ctx) (string, error) {
|
func Location(c *fiber.Ctx) (string, error) {
|
||||||
|
if Http.GeoIP == nil {
|
||||||
|
return "127.0.0.1", nil
|
||||||
|
}
|
||||||
ip := IP(c)
|
ip := IP(c)
|
||||||
_, err := Http.GeoIP.GetLocation(ip)
|
_, err := Http.GeoIP.GetLocation(ip)
|
||||||
if err != nil {
|
|
||||||
return "127.0.0.1", err
|
|
||||||
}
|
|
||||||
return "127.0.0.1", err
|
return "127.0.0.1", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -52,8 +52,10 @@ func (cfg *AppConfig) Setup() {
|
|||||||
modelFile := filepath.Join(cfg.Server.AssetPath, "rbac_model.conf")
|
modelFile := filepath.Join(cfg.Server.AssetPath, "rbac_model.conf")
|
||||||
cfg.Auth.Setup(cfg.Database.DB, modelFile)
|
cfg.Auth.Setup(cfg.Database.DB, modelFile)
|
||||||
}
|
}
|
||||||
path := MakeDir(filepath.Join(cfg.Server.AssetPath, "GeoLite2-City.mmdb"))
|
mmdbPath := filepath.Join(cfg.Server.AssetPath, "GeoLite2-City.mmdb")
|
||||||
cfg.GeoIP = ip.NewGeoIpDB(path)
|
if _, err := os.Stat(mmdbPath); err == nil {
|
||||||
|
cfg.GeoIP = ip.NewGeoIpDB(MakeDir(mmdbPath))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *AppConfig) PrepareLog() {
|
func (cfg *AppConfig) PrepareLog() {
|
||||||
|
|||||||
Reference in New Issue
Block a user