ID转换为int

This commit is contained in:
2023-07-18 08:19:48 +08:00
parent 92f2d44c19
commit cfa3224302

View File

@@ -1,9 +1,11 @@
package models
import (
"fmt"
"log"
"main/configs"
"net/http"
"strconv"
"time"
)
@@ -18,20 +20,33 @@ type Account struct {
LikeList interface{} `json:"likes" gorm:"-"`
}
func toInt(list []string) (result []int) {
for _, v := range list {
i, err := strconv.Atoi(v)
if err != nil {
log.Println(err)
continue
}
result = append(result, i)
}
return
}
func (account *Account) ReadLikeList() {
is, err := LikeImage.GetA(string(rune(account.ID)))
log.Println("ReadLikeList: account.ID = ", account.ID)
is, err := LikeImage.GetA(fmt.Sprintf("%d", account.ID))
if err != nil {
log.Println(err)
return
}
ms, err := LikeModel.GetA(string(rune(account.ID)))
ms, err := LikeModel.GetA(fmt.Sprintf("%d", account.ID))
if err != nil {
log.Println(err)
return
}
account.LikeList = map[string]interface{}{
"images": is,
"models": ms,
"images": toInt(is),
"models": toInt(ms),
}
}