{"id":13338599,"url":"https://github.com/tuya/tuya-pulsar-sdk-go","last_synced_at":"2025-05-02T02:30:51.417Z","repository":{"id":45222298,"uuid":"312219836","full_name":"tuya/tuya-pulsar-sdk-go","owner":"tuya","description":"Tuya Pulsar sdk for go ","archived":false,"fork":false,"pushed_at":"2024-12-11T06:50:25.000Z","size":72,"stargazers_count":5,"open_issues_count":6,"forks_count":13,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-06T21:22:23.066Z","etag":null,"topics":["tuya"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuya.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-11-12T08:55:53.000Z","updated_at":"2024-12-11T06:50:29.000Z","dependencies_parsed_at":"2024-11-12T14:33:18.620Z","dependency_job_id":null,"html_url":"https://github.com/tuya/tuya-pulsar-sdk-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-pulsar-sdk-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-pulsar-sdk-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-pulsar-sdk-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuya%2Ftuya-pulsar-sdk-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuya","download_url":"https://codeload.github.com/tuya/tuya-pulsar-sdk-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251972445,"owners_count":21673606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["tuya"],"created_at":"2024-07-29T19:17:02.557Z","updated_at":"2025-05-02T02:30:51.411Z","avatar_url":"https://github.com/tuya.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pulsar-client-go\n\n[English](README.md) | [中文版](README_cn.md)\n\n## Introduction\n\nTuya pulsar client SDK for Golang\n\n## Preparation\n\n1. AccessID: Provided by Tuya platform.\n2. AccessKey: provided by Tuya platform.\n3. Pulsar address: Select the pulsar address according to different business areas. You can find out the address from documents.\n\n## Example\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/base64\"\n\t\"encoding/json\"\n\n\tpulsar \"github.com/tuya/tuya-pulsar-sdk-go\"\n\t\"github.com/tuya/tuya-pulsar-sdk-go/pkg/tylog\"\n\t\"github.com/tuya/tuya-pulsar-sdk-go/pkg/tyutils\"\n)\n\nfunc main() {\n\t// SetInternalLogLevel(logrus.DebugLevel)\n\ttylog.SetGlobalLog(\"sdk\", false)\n\taccessID := \"accessID\"\n\taccessKey := \"accessKey\"\n\ttopic := pulsar.TopicForAccessID(accessID)\n\n\t// create client\n\tcfg := pulsar.ClientConfig{\n\t\tPulsarAddr: pulsar.PulsarAddrCN,\n\t}\n\tc := pulsar.NewClient(cfg)\n\n\t// create consumer\n\tcsmCfg := pulsar.ConsumerConfig{\n\t\tTopic: topic,\n\t\tAuth:  pulsar.NewAuthProvider(accessID, accessKey),\n\t}\n\tcsm, _ := c.NewConsumer(csmCfg)\n\n\t// handle message\n\tcsm.ReceiveAndHandle(context.Background(), \u0026helloHandler{AesSecret: accessKey[8:24]})\n}\n\ntype helloHandler struct {\n\tAesSecret string\n}\n\nfunc (h *helloHandler) HandlePayload(ctx context.Context, msg pulsar.Message, payload []byte) error {\n\ttylog.Info(\"payload preview\", tylog.String(\"payload\", string(payload)))\n\n\t// let's decode the payload with AES\n\tm := map[string]interface{}{}\n\terr := json.Unmarshal(payload, \u0026m)\n\tif err != nil {\n\t\ttylog.Error(\"json unmarshal failed\", tylog.ErrorField(err))\n\t\treturn nil\n\t}\n\tbs := m[\"data\"].(string)\n\tde, err := base64.StdEncoding.DecodeString(string(bs))\n\tif err != nil {\n\t\ttylog.Error(\"base64 decode failed\", tylog.ErrorField(err))\n\t\treturn nil\n\t}\n\tdecode := tyutils.EcbDecrypt(de, []byte(h.AesSecret))\n\ttylog.Info(\"aes decode\", tylog.ByteString(\"decode payload\", decode))\n\n\treturn nil\n}\n\n\n\n```\n\n## Precautions\n\n1. Make sure that the accessID and accessKey are correct.\n2. Make sure that the Pulsar address is correct, For example `pulsar+ssl://mqe.tuyaus.com:7285`.\n3. Make sure that the SDK code version you use is the latest.\n\n## About debug\n\nThrough the following code, you can see all communications with the pulsar service in the terminal.\n\n```\nfunc main(){\n\tpulsar.SetInternalLogLevel(logrus.DebugLevel)\n\t// other code\n}\n```\n\nThrough the following code, you can see the log information of `tuya_pulsar_go_sdk`.\nAt the same time, the log will be saved in the `logs/sdk.log` file.\n```\nfunc main(){\n\ttylog.SetGlobalLog(\"sdk\", false)\n}\n```\n\nIn a formal environment, you may not want the SDK logs to be output to the terminal. It is recommended that you use the following code to output the log to a file.\n```\nfunc main(){\n\ttylog.SetGlobalLog(\"sdk\", true)\n}\n```\n## Support\n\nYou can get support from Tuya with the following methods:\n\n- Tuya Smart Help Center: [https://support.tuya.com/en/help](https://support.tuya.com/en/help)\n- Technical Support Council: [https://iot.tuya.com/council](https://iot.tuya.com/council)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-pulsar-sdk-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuya%2Ftuya-pulsar-sdk-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuya%2Ftuya-pulsar-sdk-go/lists"}