{"id":207337,"date":"2025-07-08T08:48:00","date_gmt":"2025-07-08T00:48:00","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207337\/"},"modified":"2025-07-08T08:48:00","modified_gmt":"2025-07-08T00:48:00","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-golang-%e4%b8%ad%e6%8b%a5%e6%9c%89%e5%85%b7%e6%9c%89%e7%9b%b8%e5%90%8c%e6%88%90%e5%91%98%e4%bd%86%e4%b8%8d%e5%90%8c-json-%e6%a0%87%e7%ad%be%e7%9a%84%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207337\/","title":{"rendered":"\u5982\u4f55\u5728 Golang \u4e2d\u62e5\u6709\u5177\u6709\u76f8\u540c\u6210\u5458\u4f46\u4e0d\u540c JSON \u6807\u7b7e\u7684\u5f00\u53d1\u7ed3\u6784\u548c\u751f\u4ea7\u7ed3\u6784\uff1f"},"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>\u5982\u4f55\u5728 Golang \u4e2d\u62e5\u6709\u5177\u6709\u76f8\u540c\u6210\u5458\u4f46\u4e0d\u540c JSON \u6807\u7b7e\u7684\u5f00\u53d1\u7ed3\u6784\u548c\u751f\u4ea7\u7ed3\u6784\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-21 19:45:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u5728 Golang \u4e2d\u62e5\u6709\u5177\u6709\u76f8\u540c\u6210\u5458\u4f46\u4e0d\u540c JSON \u6807\u7b7e\u7684\u5f00\u53d1\u7ed3\u6784\u548c\u751f\u4ea7\u7ed3\u6784\uff1f\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u7b2c\u4e00\u6b21\u63d0\u95ee\uff01 \u6211\u6b63\u5728\u5c1d\u8bd5\u5c06\u4f7f\u7528\u76f8\u540c\u7ed3\u6784\u7684\u5f00\u53d1\u548c\u751f\u4ea7\u5206\u5f00\u3002<\/p>\n<p>\u6211\u6b63\u5728\u4f7f\u7528 airtable\uff0c\u5b83\u5c06\u8bb0\u5f55\u4f5c\u4e3a json \u53d1\u9001\uff0c\u5e76\u5e26\u6709\u6211\u4eec\u5728\u89e3\u7ec4\u65f6\u4f7f\u7528\u7684 <strong>fld<\/strong> \u6807\u7b7e\u3002<\/p>\n<pre>type airtablerecord struct {\n    name   *string  `json:\"fldaaaa,omitempty\"`\n}<\/pre>\n<p>\u6211\u6709 2 \u4e2a\u72ec\u7acb\u7684 airtable\uff1a<\/p>\n<ol>\n<li>\u7528\u4e8e\u5f00\u53d1<\/li>\n<li>\u7528\u4e8e\u751f\u4ea7<\/li>\n<\/ol>\n<p>\u5b83\u4eec\u662f\u76f8\u540c\u7684\uff0c\u53ea\u662f\u7531\u4e8e airtable \u7684\u5de5\u4f5c\u65b9\u5f0f\uff0c\u5b57\u6bb5\u88ab\u8d4b\u4e88\u4e86\u4e0d\u540c\u7684 <strong>fld<\/strong> \u6807\u7b7e<\/p>\n<p>\u6211\u7684 airtable \u573a\u5730\u7684\u56fe\u7247<\/p>\n<p>\u73b0\u5728\u8981\u5c06\u5f00\u53d1\u73af\u5883\u4e0e\u751f\u4ea7\u73af\u5883\u5206\u5f00\uff0c\u6211\u5fc5\u987b\u6839\u636e\u6211\u6307\u5411\u7684 airtable \u53d6\u6d88\u6ce8\u91ca\u6b63\u786e\u7684\u6210\u5458\u3002<\/p>\n<pre>type airtablerecord struct {\n    \/\/ development\n    name   *string  `json:\"fldaaaa,omitempty\"`\n\n    \/\/ production\n    \/\/name   *string  `json:\"fldbbbb,omitempty\"`\n}<\/pre>\n<p>\u6211\u5c06\u6b64\u7c7b\u578b\u4fdd\u7559\u5728\u5b83\u81ea\u5df1\u7684 model.go \u6587\u4ef6\u4e2d\uff0c\u4f9b\u5176\u4ed6\u5305\u4f7f\u7528\u3002<\/p>\n<p>\u6211\u8c03\u67e5\u8fc7\uff1a<\/p>\n<ul>\n<li>\u4e00\u884c\u4e2d\u6709\u591a\u4e2a json \u6807\u7b7e\uff0cgolang \u4e0d\u4f1a\u8fd9\u6837\u505a<\/li>\n<\/ul>\n<pre>type airtablerecord struct {\n    \/\/ development or production\n    name   *string  `json:\"fldaaaa,fldbbbb,omitempty\"`\n}<\/pre>\n<ul>\n<li>\u4f7f\u7528\u6784\u5efa\u6807\u7b7e\u5206\u9694\u6211\u7684\u6587\u4ef6\uff0c\u4e5f\u8bb8\u8fd9\u53ef\u884c\uff0c\u4f46\u6211\u505a\u9519\u4e86<\/li>\n<\/ul>\n<p>\u6587\u4ef61\uff1a<\/p>\n<pre>\/\/ +build dev\ntype airtablerecord struct {\n    \/\/ development\n    name   *string  `json:\"fldaaaa,omitempty\"`\n}<\/pre>\n<p>\u6587\u4ef62\uff1a<\/p>\n<pre>type AirtableRecord struct {\n    \/\/ Production\n    Name   *string  `json:\"fldBBBB,omitempty\"`\n}<\/pre>\n<ul>\n<li>\u7814\u7a76\u8fc7\u4f7f\u7528\u91cd\u65b0\u6807\u8bb0\uff0c\u4f46\u4ed6\u4eec\u7ed9\u51fa\u7684\u793a\u4f8b\u770b\u8d77\u6765\u4e0d\u50cf\u6211\u6b63\u5728\u5bfb\u627e\u7684\n<ul>\n<li>\u91cd\u65b0\u6807\u8bb0\u94fe\u63a5\uff1ahttps:\/\/pkg.go.dev\/github.com\/sevlyar\/<span>[\u7535\u5b50\u90ae\u4ef6\u53d7\u4fdd\u62a4]<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u6211\u60f3\u6839\u636e\u6211\u662f\u5728\u5f00\u53d1\u6a21\u5f0f\u8fd8\u662f\u751f\u4ea7\u6a21\u5f0f\u4e0b\u8fd0\u884c\u6765\u52a8\u6001\u66f4\u6539\u6b64\u6210\u5458\u7684\u6807\u7b7e\u3002<\/strong><\/p>\n<p><em>\u4efb\u4f55\u53ca\u6240\u6709\u5e2e\u52a9\u5c06\u4e0d\u80dc\u611f\u6fc0\uff01<\/em><\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u5982\u679c\u60a8\u5728\u6b64\u5757\u4e2d\u6536\u5230 <code>redeclared \u4f7f\u7528\u6784\u5efa\u6807\u8bb0\u7684 <\/code> \u7f16\u8bd1\u9519\u8bef\uff0c\u8bf7\u5728 prod \u6587\u4ef6\u4e0a\u6307\u5b9a\u4e00\u4e2a\u672a\u6807\u8bb0\u7684\u6807\u8bb0\uff0c\u4ee5\u907f\u514d\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<p>\u5f00\u53d1\u6587\u4ef6<\/p>\n<pre>\/\/ +build dev\ntype airtablerecord struct {\n    \/\/ development\n    name   *string  `json:\"fldaaaa,omitempty\"`\n}<\/pre>\n<p>\u4ea7\u54c1\u6587\u4ef6<\/p>\n<pre>\/\/ +build !dev\ntype airtablerecord struct {\n    \/\/ development\n    name   *string  `json:\"fldaaaa,omitempty\"`\n}<\/pre>\n<p>\u6784\u5efa<\/p>\n<pre># for dev\ngo build -tags=dev -o devrel\n# for prod\ngo build -tags=prod -o prodrel  \nor no tags for prod<\/pre>\n<p>\u81ea 1.17 \u4ee5\u6765\uff0c\u6784\u5efa\u6807\u7b7e\u683c\u5f0f\u4e5f\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u6240\u4ee5\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u662f\uff0c<\/p>\n<pre>\/\/go:build dev<\/pre>\n<p>\u4f46\u4e5f\u5e94\u8be5\u4e0e\u65e7\u7684\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u5728 Golang \u4e2d\u62e5\u6709\u5177\u6709\u76f8\u540c\u6210\u5458\u4f46\u4e0d\u540c JSON \u6807\u7b7e\u7684\u5f00\u53d1\u7ed3\u6784\u548c\u751f\u4ea7\u7ed3\u6784\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03Golang\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\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-207337","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207337","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=207337"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207337\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}