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 package models
import ( import (
"fmt"
"log" "log"
"main/configs" "main/configs"
"net/http" "net/http"
"strconv"
"time" "time"
) )
@@ -18,20 +20,33 @@ type Account struct {
LikeList interface{} `json:"likes" gorm:"-"` 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() { 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 { if err != nil {
log.Println(err) log.Println(err)
return return
} }
ms, err := LikeModel.GetA(string(rune(account.ID))) ms, err := LikeModel.GetA(fmt.Sprintf("%d", account.ID))
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return return
} }
account.LikeList = map[string]interface{}{ account.LikeList = map[string]interface{}{
"images": is, "images": toInt(is),
"models": ms, "models": toInt(ms),
} }
} }