etag write to file

handle query before db loaded
This commit is contained in:
thuanle
2024-07-14 00:48:58 +07:00
parent 12603bbf6c
commit eaeb32b421
4 changed files with 39 additions and 7 deletions

View File

@@ -9,6 +9,12 @@ import (
func HandleJson(c *gin.Context) {
ip := c.ClientIP()
if !data.Ins().IsLoaded() {
log.Error().Msg("DB is not loaded")
c.String(http.StatusInternalServerError, "Try again later")
return
}
ipData, _, err := data.Ins().Query(ip)
if err != nil {
log.Err(err).Msg("Failed to query IP")
@@ -17,6 +23,8 @@ func HandleJson(c *gin.Context) {
})
return
}
ipData["ip"] = ip
c.JSON(http.StatusOK, ipData)
}