Skip to content

Commit

Permalink
fix: 再次修复了Json意外大写的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
pysio2007 committed Jan 14, 2025
1 parent 71b0459 commit e5ac577
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ func RandomImage(c *gin.Context) {
c.Data(http.StatusOK, "image/webp", result.Data)
}

type lowerCount struct {
Key string `json:"key"`
Count int64 `json:"count"`
LastUpdated time.Time `json:"lastUpdated"`
}

func GetAPIStats(c *gin.Context) {
stats, err := models.CountsCollection.Find(context.Background(), bson.M{})
if err != nil {
Expand All @@ -307,7 +313,16 @@ func GetAPIStats(c *gin.Context) {
return
}

c.JSON(http.StatusOK, results)
lowerResults := make([]lowerCount, len(results))
for i, r := range results {
lowerResults[i] = lowerCount{
Key: r.Key,
Count: r.Count,
LastUpdated: r.LastUpdated,
}
}

c.JSON(http.StatusOK, lowerResults)
}

func GetAPIStatsByKey(c *gin.Context) {
Expand All @@ -322,7 +337,13 @@ func GetAPIStatsByKey(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, result)

lc := lowerCount{
Key: result.Key,
Count: result.Count,
LastUpdated: result.LastUpdated,
}
c.JSON(http.StatusOK, lc)
}

func GetImageCount(c *gin.Context) {
Expand Down

0 comments on commit e5ac577

Please sign in to comment.