{"id":19411491,"url":"https://github.com/volcengine/volcengine-sdk-go-rec","last_synced_at":"2026-02-25T22:32:09.590Z","repository":{"id":37721479,"uuid":"501537665","full_name":"volcengine/volcengine-sdk-go-rec","owner":"volcengine","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-16T07:44:59.000Z","size":118,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T08:22:34.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/volcengine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-09T06:51:18.000Z","updated_at":"2025-05-23T16:28:11.000Z","dependencies_parsed_at":"2024-07-16T10:12:15.400Z","dependency_job_id":null,"html_url":"https://github.com/volcengine/volcengine-sdk-go-rec","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/volcengine/volcengine-sdk-go-rec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volcengine%2Fvolcengine-sdk-go-rec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volcengine%2Fvolcengine-sdk-go-rec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volcengine%2Fvolcengine-sdk-go-rec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volcengine%2Fvolcengine-sdk-go-rec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/volcengine","download_url":"https://codeload.github.com/volcengine/volcengine-sdk-go-rec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/volcengine%2Fvolcengine-sdk-go-rec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29843428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T21:18:31.832Z","status":"ssl_error","status_checked_at":"2026-02-25T21:18:29.265Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T12:21:41.975Z","updated_at":"2026-02-25T22:32:09.573Z","avatar_url":"https://github.com/volcengine.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"volcengine data/predict api sdk, go version\n\u003cbr\u003e\n```go\npackage main\n\nimport (\n\t\"github.com/google/uuid\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/byteair\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/byteair/protocol\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/core\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/core/logs\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/core/metrics\"\n\t\"github.com/volcengine/volcengine-sdk-go-rec/core/option\"\n\t\"time\"\n)\n\nvar client byteair.Client\n\nfunc init() {\n\tclient, _ = (\u0026byteair.ClientBuilder{}).\n\t\t// 必传,租户id.\n\t\tTenantId(\"xxx\").\n\t\t// 必传,项目id.\n\t\tApplicationId(\"xxx\").\n\t\t// 必传,密钥AK.\n\t\tAK(\"xxx\").\n\t\t// 必传,密钥SK.\n\t\tSK(\"xxx\").\n\t\t// 必传,域名.\n\t\tHosts([]string{\"xxx\"}).\n\t\tBuild()\n\t// metrics上报init.建议开启,方便字节侧排查问题.\n\tmetrics.Init(\n\t\t// 域名同上\n\t\tmetrics.WithMetricsDomain(\"xxx\"),\n\t)  \n\tlogs.Level = logs.LevelInfo\n}\n\nfunc Write() {\n\t// 此处为示例数据,实际调用时需注意字段类型和格式\n\tdataList := []map[string]interface{}{\n\t\t{ // 第一条数据\n\t\t\t\"id\":            \"1\",\n\t\t\t\"title\":         \"test_title1\",\n\t\t\t\"status\":        0,\n\t\t\t\"brand\":         \"volcengine\",\n\t\t\t\"pub_time\":      1583641807,\n\t\t\t\"current_price\": 1.1,\n\t\t},\n\t\t{ // 第二条数据\n\t\t\t\"id\":            \"2\",\n\t\t\t\"title\":         \"test_title2\",\n\t\t\t\"status\":        1,\n\t\t\t\"brand\":         \"volcengine\",\n\t\t\t\"pub_time\":      1583641503,\n\t\t\t\"current_price\": 2.2,\n\t\t},\n\t}\n\t// topic为枚举值，请参考API文档\n\ttopic := \"item\"\n\t// 同步离线天级数据，需要指定日期\n\tdate, _ := time.Parse(\"2006-01-02\", \"2022-01-01\")\n\topts := []option.Option{\n\t\t// 测试数据/预同步阶段(\"pre_sync\"),历史数据同步（\"history_sync\"）和增量天级数据上传（\"incremental_sync_daily\"）\n\t\toption.WithStage(\"pre_sync\"),\n\t\t// 必传，要求每次请求的Request-Id不重复，若未传，sdk会默认为每个请求添加\n\t\toption.WithRequestId(uuid.NewString()),\n\t\t// 必传，数据产生日期，实际传输时需修改为实际日期\n\t\toption.WithDataDate(date),\n\t}\n\trsp, err := client.WriteData(dataList, topic, opts...)\n\tif err != nil {\n\t\tlogs.Error(\"[WriteData] occur error, msg:%s\", err.Error())\n\t\treturn\n\t}\n\tif !rsp.GetStatus().GetSuccess() {\n\t\tlogs.Error(\"[WriteData] failure\")\n\t\treturn\n\t}\n\tlogs.Info(\"[WriteData] success\")\n\treturn\n}\n\nfunc Done() {\n\tdate, _ := time.Parse(\"2006-01-02\", \"2022-01-01\")\n\t// 已经上传完成的数据日期，可在一次请求中传多个\n\tdateList := []time.Time{date}\n\t// 与离线天级数据传输的topic保持一致\n\ttopic := \"item\"\n\topts := []option.Option{\n\t\t// 测试数据/预同步阶段(\"pre_sync\"),历史数据同步（\"history_sync\"）和增量天级数据上传（\"incremental_sync_daily\"）\n\t\toption.WithStage(\"pre_sync\"),\n\t\t// 必传，要求每次请求的Request-Id不重复，若未传，sdk会默认为每个请求添加\n\t\toption.WithRequestId(uuid.NewString()),\n\t}\n\trsp, err := client.Done(dateList, topic, opts...)\n\tif err != nil {\n\t\tlogs.Error(\"[Done] occur error, msg: %s\", err.Error())\n\t\treturn\n\t}\n\tif !rsp.GetStatus().GetSuccess() {\n\t\tlogs.Error(\"[Done] failure\")\n\t\treturn\n\t}\n\tlogs.Info(\"[Done] success\")\n\treturn\n}\n\nfunc Predict() {\n\treq := \u0026protocol.PredictRequest{\n\t\tUser: \u0026protocol.PredictUser{\n\t\t\tUid: \"uid1\",\n\t\t},\n\t\tContext: \u0026protocol.PredictContext{\n\t\t\tSpm:   \"1$##$2$##$3$##$4\",\n\t\t\tExtra: map[string]string{\"extra_key\": \"extra_value\"},\n\t\t},\n\t\tCandidateItems: []*protocol.PredictCandidateItem{\u0026protocol.PredictCandidateItem{\n\t\t\tId: \"item_id1\",\n\t\t}},\n\t\tParentItem: \u0026protocol.PredictParentItem{\n\t\t\tId: \"item_id2\",\n\t\t},\n\t}\n\topts := []option.Option{\n\t\toption.WithRequestId(uuid.NewString()),\n\t\toption.WithScene(\"default\"),\n\t\t// 是否开启SPM路由.开启的话需要保证请求体里的SPM存在且绑定了栏位.\n\t\t// server会根据body里的SPM路由到选择的栏位.\n\t\toption.WithHeaders(map[string]string{\n\t\t\t\"Enable-spm-route\": \"true\",\n\t\t}),\n\t}\n\trsp, err := client.Predict(req, opts...)\n\tif err != nil {\n\t\tlogs.Error(\"[predict] occur error, msg: %s\", err.Error())\n\t\treturn\n\t}\n\tif !rsp.GetSuccess() {\n\t\tlogs.Error(\"[predict] failure\")\n\t\treturn\n\t}\n\trsp.GetRequestId()\n\tlogs.Info(\"[predict] success\")\n}\n\nfunc Callback() {\n\treq := \u0026protocol.CallbackRequest{\n\t\tUid:   \"uid1\",\n\t\tScene: \"default\",\n\t\tItems: []*protocol.CallbackItem{\n\t\t\t{\n\t\t\t\tId:    \"item_id1\",\n\t\t\t\tPos:   \"pos1\",\n\t\t\t\tExtra: \"{\\\"reason\\\":\\\"exposure\\\"}\",\n\t\t\t},\n\t\t\t{\n\t\t\t\tId:    \"item_id1\",\n\t\t\t\tPos:   \"pos1\",\n\t\t\t\tExtra: \"{\\\"reason\\\":\\\"filter\\\"}\",\n\t\t\t},\n\t\t},\n\t\tPredictRequestId: \"ds12ad61hnwo\",\n\t\tContext: \u0026protocol.CallbackContext{\n\t\t\tSpm:   \"1$##$2$##$3$##$4\",\n\t\t\tExtra: map[string]string{\"extra_key\": \"extra_value\"},\n\t\t},\n\t\tExtra: nil,\n\t}\n\topts := []option.Option{\n\t\toption.WithRequestId(uuid.NewString()),\n\t}\n\trsp, err := client.Callback(req, opts...)\n\tif err != nil {\n\t\tlogs.Error(\"[callback] occur error, msg: %s\", err.Error())\n\t\treturn\n\t}\n\tif !rsp.GetSuccess() {\n\t\tlogs.Error(\"[callback] failure\")\n\t\treturn\n\t}\n\tlogs.Info(\"[callback] success\")\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolcengine%2Fvolcengine-sdk-go-rec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvolcengine%2Fvolcengine-sdk-go-rec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvolcengine%2Fvolcengine-sdk-go-rec/lists"}