You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
851 B
41 lines
851 B
package archive |
|
|
|
import ( |
|
"context" |
|
"net/url" |
|
"strconv" |
|
|
|
"go-common/library/ecode" |
|
"go-common/library/xstr" |
|
|
|
"github.com/pkg/errors" |
|
) |
|
|
|
const ( |
|
_realteURL = "/recsys/related" |
|
) |
|
|
|
// RelateAids get relate by aid |
|
func (d *Dao) RelateAids(c context.Context, aid int64, ip string) (aids []int64, err error) { |
|
params := url.Values{} |
|
params.Set("key", strconv.FormatInt(aid, 10)) |
|
var res struct { |
|
Code int `json:"code"` |
|
Data []*struct { |
|
Value string `json:"value"` |
|
} `json:"data"` |
|
} |
|
if err = d.client.Get(c, d.relateURL, ip, params, &res); err != nil { |
|
return |
|
} |
|
if res.Code != ecode.OK.Code() { |
|
err = errors.Wrap(ecode.Int(res.Code), d.relateURL+"?"+params.Encode()) |
|
return |
|
} |
|
if len(res.Data) != 0 { |
|
if aids, err = xstr.SplitInts(res.Data[0].Value); err != nil { |
|
err = errors.Wrap(err, res.Data[0].Value) |
|
} |
|
} |
|
return |
|
}
|
|
|