コード例 #1
0
ファイル: analytics.go プロジェクト: cj123/analytics
func statisticsGET(c *gin.Context) {
	a := client.Analytics{
		Identifier:  c.Param("identifier"),
		BuildID:     c.Param("buildid"),
		Request:     c.Param("request"),
		DownloadNow: c.DefaultQuery("downloadNow", "false") == "true",
	}

	downloadCount, err := redisClient.Get(a.GetKey()).Int64()

	if err == redis.Nil {
		downloadCount = 0
	}

	c.Header("Access-Control-Allow-Origin", "*")
	c.Header("Access-Control-Expose-Headers", "X-Data-Location, X-Server-Location")
	c.JSON(http.StatusOK, gin.H{"count": downloadCount})
}
コード例 #2
0
ファイル: analytics.go プロジェクト: cj123/analytics
func trackPOST(c *gin.Context) {
	var analytics client.Analytics

	if err := c.BindJSON(&analytics); err != nil {
		c.JSON(http.StatusBadRequest, NewJSONError(err.Error()))
		return
	}

	count, err := redisClient.Get(analytics.GetKey()).Int64()

	if err == redis.Nil {
		count = 1
	} else {
		count++
	}

	redisClient.Set(analytics.GetKey(), count, 0)

	c.JSON(http.StatusCreated, NewJSONSuccess())
}