feat(data): 添加数据格式支持 更改数据写入读取
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
All checks were successful
构建Docker镜像 / build-and-deploy (push) Successful in 1m33s
This commit is contained in:
@@ -13,50 +13,63 @@ func ListTokenHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func CreateTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
return
|
||||
} else if c.Query("dedup_object") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
||||
//解析输入数据
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
DedupObject string `form:"dedup_object" binding:"required"`
|
||||
DataFormat string `form:"data_format" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := db.CreateToken(c.Query("token"), c.Query("dedup_object"))
|
||||
//创建Token
|
||||
err := db.CreateToken(input.Token, input.DedupObject, input.DataFormat)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
//返回
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
func UpdateTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
return
|
||||
} else if c.Query("dedup_object") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "dedup_object不能为空"})
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
DedupObject string `form:"dedup_object" binding:"required"`
|
||||
DataFormat string `form:"data_format" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := db.UpdateToken(c.Query("token"), c.Query("dedup_object"))
|
||||
err := db.UpdateToken(input.Token, input.DedupObject, input.DataFormat)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
func DeleteTokenHandler(c *gin.Context) {
|
||||
if c.Query("token") == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "token不能为空"})
|
||||
input := struct {
|
||||
Token string `form:"token" binding:"required"`
|
||||
}{}
|
||||
if err := c.ShouldBindQuery(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "参数不能为空 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
err := db.DeleteToken(c.Query("token"))
|
||||
err := db.DeleteToken(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"result": "ok"})
|
||||
}
|
||||
|
||||
@@ -74,15 +87,22 @@ func GetTokenInfoHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取去重对象失败 " + err.Error()})
|
||||
return
|
||||
}
|
||||
dataFormat, err := db.GetDataFormat(input.Token)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取数据格式失败 " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
output := struct {
|
||||
Token string `json:"token"`
|
||||
DedupObject string `json:"dedup_object"`
|
||||
DataFormat string `json:"data_format"`
|
||||
DedupItemsNumber int64 `json:"dedup_items_number"`
|
||||
CacheListNumber int64 `json:"cache_list_number"`
|
||||
}{}
|
||||
output.Token = input.Token
|
||||
output.DedupObject = dedupObject
|
||||
output.DataFormat = dataFormat
|
||||
output.DedupItemsNumber = global.RDB.BFCard(global.RCtx, "dedup:"+input.Token+":"+dedupObject).Val()
|
||||
output.CacheListNumber = global.RDB.LLen(global.RCtx, "list:"+input.Token).Val()
|
||||
|
||||
|
Reference in New Issue
Block a user