package recomapi import ( "fmt" "net/http" "strconv" "videoweb/pub/common/log" "videoweb/pub/common/srvdef" "videoweb/pub/common/utils" ) func GetRecomItems(url string, key string, userId int64, writeBack string, size int64) ( []int64, *srvdef.SrvErr) { reqUrl := fmt.Sprintf("%s/api/recommend/%d?n=%d&write-back=%s", url, userId, size, writeBack) var resp []string header := map[string]string{"X-API-Key": key} code, err := utils.GetWithJResp(&resp, reqUrl, header, nil) if err != nil { log.Error("recomapi:GetRecomItems GetWithJResp failed", log.Any("reqUrl", reqUrl), log.E(err)) return nil, srvdef.New(srvdef.Err, "", "") } if code != http.StatusOK { log.Error("recomapi:GetRecomItems GetWithJResp code error.", log.Any("reqUrl", reqUrl), log.Any("code", code)) return nil, srvdef.New(srvdef.Err, "", "") } itemIds := make([]int64, 0) for _, v := range resp { id, err := strconv.ParseInt(v, 10, 64) if err == nil { itemIds = append(itemIds, id) } } return itemIds, nil }