package api import ( "github.com/gin-gonic/gin" "net/http" "strconv" "zggsong.cn/sandstone/server/dao" "zggsong.cn/sandstone/server/response" "zggsong.cn/sandstone/server/util" ) func ListRecords(ctx *gin.Context) { var datas []response.Data var data response.Data limit, err := strconv.ParseInt(ctx.Query("limit"), 10, 64) if err != nil { ctx.JSON(http.StatusOK, response.Response{ Code: http.StatusBadRequest, Message: "limit must be a number", }) return } page, err := strconv.ParseInt(ctx.Query("page"), 10, 64) if err != nil { ctx.JSON(http.StatusOK, response.Response{ Code: http.StatusBadRequest, Message: "page must be a number", }) return } arrayData, total, err := dao.Find(limit, page) if err != nil { ctx.JSON(http.StatusOK, response.Response{ Code: http.StatusInternalServerError, Message: err.Error(), }) return } if arrayData == nil { ctx.JSON(http.StatusOK, response.Response{ Code: http.StatusLengthRequired, Message: "no data", }) return } for _, aData := range arrayData { data.CreateTime = aData.CreateTime data.UploadTime = aData.UploadTime data.Line = aData.Line data.Machine = aData.Machine data.KeyName = aData.KeyName data.Size = aData.Size data.Url = util.GetUrl(aData.KeyName) data.Tags = util.GetTags(aData.KeyName) datas = append(datas, data) } ctx.JSON(http.StatusOK, response.Response{ Code: http.StatusOK, Message: "success", Data: datas, Total: total, Page: page, }) }