{"id":207578,"date":"2025-07-08T08:16:37","date_gmt":"2025-07-08T00:16:37","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207578\/"},"modified":"2025-07-08T08:16:37","modified_gmt":"2025-07-08T00:16:37","slug":"%e5%b0%9d%e8%af%95%e5%b0%86%e5%88%87%e7%89%87%e6%a0%bc%e5%bc%8f%e5%8c%96%e4%b8%ba%e7%89%b9%e5%ae%9a%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207578\/","title":{"rendered":"\u5c1d\u8bd5\u5c06\u5207\u7247\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u683c\u5f0f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5c1d\u8bd5\u5c06\u5207\u7247\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u683c\u5f0f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-23 18:57:27<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2aGolang\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300a\u5c1d\u8bd5\u5c06\u5207\u7247\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u683c\u5f0f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u60a8\u597d\uff0c\u6211\u662f Go \u65b0\u624b\uff0c\u4e4b\u524d\u6211\u662f JavaScript \u5f00\u53d1\u4eba\u5458<\/p>\n<p><strong>\u6211\u4ecerabbitMq\u83b7\u53d6\u4fe1\u606f\u53d8\u91cf\u4f5c\u4e3a[]\u5b57\u7b26\u4e32\u5e76\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u51fd\u6570 \u8be5\u51fd\u6570\u5c06\u6267\u884c\u4e00\u4e9b\u5916\u90e8 api \u8c03\u7528\uff0c\u5f53\u6211\u5c1d\u8bd5\u4f7f\u7528\u4e0e\u6211\u4ece\u4ee3\u7801\u5e93\u4e2d\u7684rabbitMq \u83b7\u5f97\u7684\u6570\u636e\u76f8\u540c\u7684 Postman \u8fdb\u884c\u8c03\u7528\u65f6\uff0c\u5b83\u6b63\u5728\u6309\u9884\u671f\u5de5\u4f5c\uff0c\u4f46\u662f\u5f53\u6211\u5c1d\u8bd5\u5728 golang http \u8c03\u7528\u7684\u5e2e\u52a9\u4e0b\u8c03\u7528\u8be5 api \u65f6\uff0c\u6211\u662f\u9762\u4e34\u7684\u95ee\u9898\u662f\u9644\u4e0apostman\u8bf7\u6c42postman\u4ee3\u7801\u7684\u5c4f\u5e55\u622a\u56fe\uff0c\u6211\u7684\u4ee3\u7801\u5e93\u4ee5\u53ca\u4fe1\u606f\u53d8\u91cf\u548c\u6211\u7684rabbitMq\u6570\u636e\u7684\u6253\u5370<\/strong> postman api\u8c03\u7528\u7684\u56fe\u50cfpostman api\u8bf7\u6c42\u4ee3\u7801\u7684\u56fe\u50cf\u4e0erabbitMq\u961f\u5217\u6570\u636e\u7684Golang\u56fe\u50cf\u6253\u5370\u6211\u7684\u51fd\u6570\u4e0b\u7684info\u53d8\u91cf\u68c0\u67e5\u8bf7\u6c42\u4ee3\u7801\u5e93\u6709\u54ea\u4e9b\u4fe1\u606f\u6765\u8bbf\u95ee\u5916\u90e8 api<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>marshalindent<\/code>\u3002\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u524d\u7f00\uff08\u5982\u679c\u60a8\u9700\u8981\u66f4\u591a <code>\\n<\/code>\uff0c\u53ef\u4ee5\u5c06\u5176\u653e\u5728\u8fd9\u91cc\uff09\uff0c\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u662f\u7f29\u8fdb\u5b57\u7b26\uff08\u6b63\u5982\u6211\u6240\u8bf4\u7684 <code>\\t<\/code>\uff09\u3002<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"encoding\/json\"\n)\n\nfunc main() {\n    info := []map[string]interface{}{\n        {\"eventType\": \"MyEvent\", \"account\": 5, \"amount\": 7000000, \"product\": \"Dairy\"},\n    }\n\n    r, e := json.MarshalIndent(info, \"\", \"\\t\")\n    if e != nil {\n        panic(e)        \n    }\n    \n    fmt.Println(fmt.Sprintf(\"%q\", string(r)))\n}\n\n\/\/ output: \"[\\n\\t{\\n\\t\\t\\\"account\\\": 5,\\n\\t\\t\\\"amount\\\": 7000000,\\n\\t\\t\\\"eventType\\\": \\\"MyEvent\\\",\\n\\t\\t\\\"product\\\": \\\"Dairy\\\"\\n\\t}\\n]\"\n<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5c1d\u8bd5\u5c06\u5207\u7247\u683c\u5f0f\u5316\u4e3a\u7279\u5b9a\u683c\u5f0f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207578","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207578"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207578\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}