first commit

This commit is contained in:
thuanle
2024-07-13 23:58:47 +07:00
parent 5a47b94c85
commit 4bb5ee09f0
23 changed files with 650316 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package db_updater
import (
"github.com/robfig/cron/v3"
"github.com/rs/zerolog/log"
"thuanle.me/ip-info/configs"
"thuanle.me/ip-info/internal/data"
)
func StartUpdateDbService() {
c := cron.New()
_, _ = c.AddFunc("@daily", fetchDbs)
c.Start()
fetchDbs()
}
func fetchDbs() {
newFlag := false
for _, url := range configs.GeoDbSourcePaths {
newFlag = newFlag || download(url)
}
if newFlag {
log.Info().Msg("New DB downloaded. Recreating mmdb")
_ = mergeMmdb()
err := data.Ins().Reload()
if err != nil {
log.Err(err).Msg("Failed to reload mmdb")
return
}
}
}