{"id":206428,"date":"2025-06-12T14:46:02","date_gmt":"2025-06-12T06:46:02","guid":{"rendered":"https:\/\/server.hk\/cnblog\/206428\/"},"modified":"2025-06-12T14:46:02","modified_gmt":"2025-06-12T06:46:02","slug":"%e5%a6%82%e4%bd%95%e7%94%a8-go-%e8%af%ad%e8%a8%80%e5%b0%86%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e8%bd%ac%e5%8c%96%e4%b8%ba%e7%b1%bb%e4%bc%bc-rdm-%e7%9a%84%e7%9b%ae%e5%bd%95%e6%a0%91%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/206428\/","title":{"rendered":"\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f"},"content":{"rendered":"<p>\u5bf9\u4e8e\u4e00\u4e2aGOLANG\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0cGOLANG\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\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\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,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/173133365267320e14c4e1b.jpg\" class=\"aligncenter\">,<br \/>\n<strong>\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u76ee\u5f55\u7ed3\u6784\uff1a\u4e00\u79cd\u4fbf\u6377\u9ad8\u6548\u7684 go \u8bed\u8a00\u7b97\u6cd5<\/strong>,\u60f3\u8981\u5b9e\u73b0\u7c7b\u4f3c rdm \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\u4f46\u82e6\u601d\u51a5\u60f3\u5374\u96be\u6709\u7a81\u7834\uff1f\u522b\u62c5\u5fc3\uff0c\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e2a\u7b80\u6d01\u9ad8\u6548\u7684 go \u8bed\u8a00\u89e3\u51b3\u65b9\u6848\uff0c\u5e2e\u4f60\u5728\u590d\u6742\u7684\u6570\u636e\u4e2d\u7406\u51fa\u6e05\u6670\u7684\u6761\u7406\u3002,<br \/>\n<strong>\u4efb\u52a1\uff1a<\/strong>\u5c06\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u5982 rdm \u822c\u7684\u76ee\u5f55\u6811\u7ed3\u6784\u3002\u6570\u7ec4\u4e2d\u5143\u7d20\u7531\u5192\u53f7\uff08:\uff09\u5206\u9694\uff0c\u8868\u793a\u76ee\u5f55\u5c42\u7ea7\u5173\u7cfb\u3002,<br \/>\n<strong>\u793a\u4f8b\u8f93\u5165\uff1a<\/strong>,<br \/>\n<strong>\u9884\u671f\u8f93\u51fa\uff1a<\/strong>,<br \/>\n<strong>\u7b97\u6cd5\u6b65\u9aa4\uff1a<\/strong>,<br \/>\n<strong>\u6700\u7ec8\u4ee3\u7801\uff1a<\/strong>,\u8fd0\u7528\u6b64\u7b97\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8f7b\u800c\u6613\u4e3e\u5730\u5b9e\u73b0\u4efb\u610f\u590d\u6742\u6027\u7684\u4e8c\u7ef4\u6570\u7ec4\u5230\u76ee\u5f55\u6811\u7684\u8f6c\u6362\uff0c\u5e76\u751f\u6210\u6e05\u6670\u3001\u7f8e\u89c2\u7684\u6811\u72b6\u7ed3\u6784\u3002,\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01,\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u76ee\u5f55\u7ed3\u6784\uff1a\u4e00\u79cd\u4fbf\u6377\u9ad8\u6548\u7684 go \u8bed\u8a00\u7b97\u6cd5,\u5bf9\u4e8e\u4e00\u4e2aGOLANG\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0cGOLANG\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\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\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,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f<\/span><\/p>\n<h1>\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f<\/h1>\n<p><span>2024-11-11 22:01:08<\/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\uff0cGOLANG\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\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\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><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/173133365267320e14c4e1b.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u76ee\u5f55\u7ed3\u6784\uff1a\u4e00\u79cd\u4fbf\u6377\u9ad8\u6548\u7684 go \u8bed\u8a00\u7b97\u6cd5<\/strong><\/p>\n<p>\u60f3\u8981\u5b9e\u73b0\u7c7b\u4f3c rdm \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\u4f46\u82e6\u601d\u51a5\u60f3\u5374\u96be\u6709\u7a81\u7834\uff1f\u522b\u62c5\u5fc3\uff0c\u8fd9\u7bc7\u6587\u7ae0\u5c06\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4e2a\u7b80\u6d01\u9ad8\u6548\u7684 go \u8bed\u8a00\u89e3\u51b3\u65b9\u6848\uff0c\u5e2e\u4f60\u5728\u590d\u6742\u7684\u6570\u636e\u4e2d\u7406\u51fa\u6e05\u6670\u7684\u6761\u7406\u3002<\/p>\n<p><strong>\u4efb\u52a1\uff1a<\/strong>\u5c06\u7ed9\u5b9a\u7684\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u5982 rdm \u822c\u7684\u76ee\u5f55\u6811\u7ed3\u6784\u3002\u6570\u7ec4\u4e2d\u5143\u7d20\u7531\u5192\u53f7\uff08:\uff09\u5206\u9694\uff0c\u8868\u793a\u76ee\u5f55\u5c42\u7ea7\u5173\u7cfb\u3002<\/p>\n<p><strong>\u793a\u4f8b\u8f93\u5165\uff1a<\/strong><\/p>\n<pre>values := []string{\n    \"answer:aa:bb\",\n    \"answer:aa:cc\",\n    \"question:book1\",\n    \"question:book1:answer\",\n    \"question:book1:answer:name1\",\n    \"question:book1:answer:name2\",\n    \"timeout_1\",\n    \"timeout_2\",\n}<\/pre>\n<p><strong>\u9884\u671f\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>[\n    {\n        \"name\": \"answer\",\n        \"child\": [\n            {\n                \"name\": \"aa\",\n                \"child\": [\n                    {\n                        \"name\": \"bb\",\n                        \"value\": \"answer:aa:bb\",\n                        \"child\": []\n                    },\n                    {\n                        \"name\": \"cc\",\n                        \"value\": \"answer:aa:cc\",\n                        \"child\": []\n                    }\n                ]\n            }\n        ]\n    },\n    {\n        \"name\": \"question\",\n        \"child\": [\n            {\n                \"name\": \"book1\",\n                \"value\": \"question:book1\",\n                \"child\": [\n                    {\n                        \"name\": \"answer\",\n                        \"child\": [\n                            {\n                                \"name\": \"name1\",\n                                \"value\": \"question:book1:answer:name1\",\n                                \"child\": []\n                            },\n                            {\n                                \"name\": \"name2\",\n                                \"value\": \"question:book1:answer:name2\",\n                                \"child\": []\n                            }\n                        ]\n                    }\n                ]\n            }\n        ]\n    },\n    {\n        \"name\": \"timeout_1\",\n        \"value\": \"timeout_1\",\n        \"child\": []\n    },\n    {\n        \"name\": \"timeout_2\",\n        \"value\": \"timeout_2\",\n        \"child\": []\n    }\n]<\/pre>\n<p><strong>\u7b97\u6cd5\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u521d\u59cb\u5316\u4e00\u4e2a\u6839\u8282\u70b9\u6620\u5c04\u8868 root\u3002<\/li>\n<li>\u904d\u5386\u7ed9\u5b9a\u7684\u6570\u7ec4\u503c\u3002<\/li>\n<li>\u5c06\u6570\u7ec4\u503c\u6309\u5192\u53f7\u5206\u9694\u4e3a\u952e\u5217\u8868 keys\u3002<\/li>\n<li>\u6309\u952e\u5217\u8868\u7684\u987a\u5e8f\u904d\u5386 root\u3002\u5982\u679c\u9047\u5230\u7684\u952e\u662f\u73b0\u6709\u5b50\u8282\u70b9\uff0c\u5219\u8fdb\u5165\u8be5\u5b50\u8282\u70b9\u7684\u6620\u5c04\u8868\u4e2d\uff1b\u5426\u5219\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u5b50\u8282\u70b9\u5e76\u8fdb\u5165\u8be5\u5b50\u8282\u70b9\u7684\u6620\u5c04\u8868\u4e2d\u3002<\/li>\n<li>\u5bf9\u4e8e\u952e\u5217\u8868\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u952e\uff08\u8868\u793a\u53f6\u5b50\u8282\u70b9\uff09\uff0c\u521b\u5efa\u4e00\u4e2a\u53ea\u5305\u542b\u540d\u79f0\u548c\u503c\u7684\u8282\u70b9\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u5f53\u524d\u5b50\u8282\u70b9\u6620\u5c04\u8868\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u6700\u7ec8\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>package main\n\nimport (\n    \"encoding\/json\"\n    \"strings\"\n)\n\nfunc main() {\n    root := make(map[string]Node)\n\n    for _, value := range values {\n        t := root\n        keys := strings.Split(value, \":\")\n        l := len(keys)\n        for i := 0; i &lt; l-1; i++ {\n            k := keys[i]\n            if tm, has := t[k]; has {\n                t = tm.Child\n            } else {\n                t[k] = Node{\n                    Name:  k,\n                    Child: map[string]Node{},\n                }\n                t = t[k].Child\n            }\n        }\n        t[value] = Node{\n            Name:  keys[l-1],\n            Value: value,\n            Child: nil,\n        }\n    }\n    r, _ := json.Marshal(root)\n    println(string(r))\n}\n\ntype Node struct {\n    Name  string\n    Value string\n    Child map[string]Node\n}<\/pre>\n<p>\u8fd0\u7528\u6b64\u7b97\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8f7b\u800c\u6613\u4e3e\u5730\u5b9e\u73b0\u4efb\u610f\u590d\u6742\u6027\u7684\u4e8c\u7ef4\u6570\u7ec4\u5230\u76ee\u5f55\u6811\u7684\u8f6c\u6362\uff0c\u5e76\u751f\u6210\u6e05\u6670\u3001\u7f8e\u89c2\u7684\u6811\u72b6\u7ed3\u6784\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u7528 Go \u8bed\u8a00\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u5316\u4e3a\u7c7b\u4f3c RDM \u7684\u76ee\u5f55\u6811\u7ed3\u6784\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4e3a\u4ec0\u4e48 Vue \u4e2d\u4f7f\u7528 v-html \u6e32\u67d3 HTML \u65f6\uff0cem \u6807\u7b7e\u65e0\u6cd5\u89e3\u6790\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u4f7f\u7528 setuptools \u6253\u5305\u540e\uff0c\u4e3a\u4ec0\u4e48\u53ef\u6267\u884c\u6587\u4ef6\u6743\u9650\u4e0d\u4e00\u81f4\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u4e00\u4e2aGOLANG\u5f00\u53d1\u8005\u6765\u8bf4\uff0c&#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-206428","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206428","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=206428"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/206428\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=206428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=206428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=206428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}