diff --git a/app/app.go b/app/app.go index ad5b379..025139c 100755 --- a/app/app.go +++ b/app/app.go @@ -36,11 +36,11 @@ func LoadBuiltInMiddlewares(app *config.AppConfig) { func Location(c *fiber.Ctx) (string, error) { + if Http.GeoIP == nil { + return "127.0.0.1", nil + } ip := IP(c) _, err := Http.GeoIP.GetLocation(ip) - if err != nil { - return "127.0.0.1", err - } return "127.0.0.1", err } diff --git a/config/config.go b/config/config.go index b175948..86c183b 100755 --- a/config/config.go +++ b/config/config.go @@ -52,8 +52,10 @@ func (cfg *AppConfig) Setup() { modelFile := filepath.Join(cfg.Server.AssetPath, "rbac_model.conf") cfg.Auth.Setup(cfg.Database.DB, modelFile) } - path := MakeDir(filepath.Join(cfg.Server.AssetPath, "GeoLite2-City.mmdb")) - cfg.GeoIP = ip.NewGeoIpDB(path) + mmdbPath := filepath.Join(cfg.Server.AssetPath, "GeoLite2-City.mmdb") + if _, err := os.Stat(mmdbPath); err == nil { + cfg.GeoIP = ip.NewGeoIpDB(MakeDir(mmdbPath)) + } } func (cfg *AppConfig) PrepareLog() {