package util import ( "context" "fmt" "github.com/spf13/viper" "github.com/zhenghaoz/gorse/client" "time" ) var gorse *client.GorseClient func init() { gorse = client.NewGorseClient(viper.GetString("gorse.addr"), "") } func Recommend(uid, goodsId, tie uint) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() t := time.Unix(int64(tie), 0) date := t.Format("2006-01-02") _, err := gorse.InsertFeedback(ctx, []client.Feedback{ {FeedbackType: "star", UserId: fmt.Sprintf("%d", uid), ItemId: fmt.Sprintf("%d", goodsId), Timestamp: date}, }) if err != nil { fmt.Println(err.Error()) } } func GetRecommend(uid uint, cnt int) (goods []string, err error) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() category, err := gorse.GetItemRecommendWithCategory(ctx, fmt.Sprintf("%d", uid), "", "", "", 0, cnt) return category, err }