{"id":117442,"date":"2026-10-24T21:48:22","date_gmt":"2026-10-24T13:48:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117442.html"},"modified":"2026-10-24T21:48:22","modified_gmt":"2026-10-24T13:48:22","slug":"go-%e9%a1%b9%e7%9b%ae%e9%aa%a8%e6%9e%b6-25-%e4%b8%aa%e7%9b%ae%e5%bd%95%e5%8f%aa%e7%94%a8-9-%e4%b8%aa%ef%bc%9a%e9%94%99%e8%af%af%e7%a0%81%e9%94%99-1-%e4%bd%8d%ef%bc%8c%e7%ba%bf%e4%b8%8a%e6%8e%92","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117442.html","title":{"rendered":"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6"},"content":{"rendered":"<p>\u4f60\u597d&#xff0c;\u6211\u662f\u5229\u5a01\u5c14xu\u3002<\/p>\n<p>\u8fd9\u662f\u300c\u9879\u76ee\u5b9e\u6218\u300d\u4e13\u680f\u7684\u7b2c\u4e00\u7bc7\u3002\u524d\u9762\u5728\u9762\u8bd5\u516b\u80a1\u548c\u4fdd\u59c6\u7ea7\u7cfb\u5217\u91cc\u804a\u4e86\u592a\u591a\u539f\u7406&#xff0c;\u8fd9\u6b21\u6362\u4e2a\u89d2\u5ea6&#xff1a;\u4ece 0 \u628a\u4e00\u4e2a Go \u670d\u52a1\u642d\u8d77\u6765&#xff0c;\u5230\u5e95\u8be5\u5efa\u54ea\u4e9b\u76ee\u5f55\u3001\u63a5\u53e3\u600e\u4e48\u5b9a\u3001\u9519\u8bef\u7801\u600e\u4e48\u7f16\u3001\u914d\u7f6e\u600e\u4e48\u653e\u3002\u8fd9\u4e00\u7bc7\u662f\u6574\u4e2a\u4e13\u680f\u7684\u5730\u57fa&#xff0c;\u540e\u9762\u6240\u6709\u5b9e\u6218\u9879\u76ee\u90fd\u6309\u8fd9\u5957\u9aa8\u67b6\u6765\u3002<\/p>\n<p>\u70b9\u540d\u4e00\u4e0b\u53d7\u4f17&#xff1a;\u80fd\u5199 Go\u3001\u80fd\u8dd1\u901a Gin \u7684 CRUD&#xff0c;\u4f46\u6ca1\u4ece\u96f6\u642d\u8fc7\u4e00\u4e2a\u80fd\u88ab\u4e09\u4e2a\u4eba\u4ee5\u4e0a\u534f\u4f5c\u7684\u5de5\u7a0b\u9aa8\u67b6\u7684\u540c\u5b66\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5728\u7ef4\u62a4\u4e00\u4e2a&#034;\u6240\u6709\u4ee3\u7801\u90fd\u585e main.go&#034;\u7684\u9879\u76ee&#xff0c;\u8fd9\u7bc7\u57fa\u672c\u5c31\u662f\u4f60\u7684\u6539\u9020\u6e05\u5355\u3002<\/p>\n<p>\u5efa\u8bae\u5148\u6536\u85cf\u2014\u2014\u76ee\u5f55\u53d6\u820d\u8868\u548c\u9519\u8bef\u7801\u5206\u6bb5\u8868\u662f\u5e72\u6d3b\u7684\u901f\u67e5\u4ef6&#xff0c;\u4e0d\u662f\u8bfb\u5b8c\u5c31\u5fd8\u7684\u723d\u6587\u3002<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\n<ul>\n<li>\u4e00\u3001\u5148\u770b\u7ed3\u8bba&#xff1a;25 \u4e2a\u76ee\u5f55&#xff0c;\u6211\u4eec\u53ea\u7559\u4e86 9 \u4e2a<\/li>\n<li>\n<ul>\n<li>\u6211\u4eec\u73b0\u5728\u7684\u9aa8\u67b6<\/li>\n<\/ul>\n<\/li>\n<li>\u4e8c\u3001\/internal\u3001\/cmd\u3001\/vendor \u4e09\u4e2a\u5fc5\u987b\u8bb2\u6e05\u7684<\/li>\n<li>\n<ul>\n<li>\/internal \u4e0d\u662f\u7ea6\u5b9a&#xff0c;\u662f\u7f16\u8bd1\u5668\u5f3a\u5236\u7684<\/li>\n<li>\/cmd \u7684\u4e09\u6761\u7eaa\u5f8b<\/li>\n<li>\/vendor \u4ec0\u4e48\u65f6\u5019\u8be5\u7528&#xff0c;\u4ec0\u4e48\u65f6\u5019\u7edd\u5bf9\u522b\u7528<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001API \u8bbe\u8ba1&#xff1a;5 \u6761\u786c\u89c4\u5219\u548c 3 \u4e2a\u53cd\u4f8b<\/li>\n<li>\u56db\u3001\u5b89\u5168\u6027\u4e0e\u5e42\u7b49\u6027&#xff1a;\u90a3\u5f20\u8868\u683c\u80cc\u540e\u662f\u771f\u91d1\u767d\u94f6<\/li>\n<li>\u4e94\u3001\u9519\u8bef\u7801&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5168\u5c40\u7edf\u4e00&#xff0c;\u516d\u6bb5\u7f16\u53f7\u600e\u4e48\u7b97<\/li>\n<li>\n<ul>\n<li>\u4e3a\u4ec0\u4e48\u4e0d\u63a8\u8350\u5168\u5c40\u9519\u8bef\u7801<\/li>\n<li>\u6309\u9879\u76ee &#043; \u670d\u52a1 &#043; \u6a21\u5757 &#043; \u9519\u8bef\u7801\u56db\u7ea7\u7f16\u53f7<\/li>\n<li>Go \u91cc\u7684\u843d\u5730\u5199\u6cd5<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001HTTP \u72b6\u6001\u7801\u4e0e\u54cd\u5e94\u4f53&#xff1a;\u4e09\u5c42\u5404\u7ba1\u4ec0\u4e48<\/li>\n<li>\n<ul>\n<li>\u72b6\u6001\u7801\u7684\u5206\u5de5<\/li>\n<li>\u7edf\u4e00\u54cd\u5e94\u7ed3\u6784<\/li>\n<\/ul>\n<\/li>\n<li>\u4e03\u3001\u914d\u7f6e&#xff1a;\u56db\u7c7b\u7684\u8fb9\u754c\u5728\u54ea<\/li>\n<li>\n<ul>\n<li>\u914d\u7f6e\u8bbe\u8ba1 6 \u6761\u7eaa\u5f8b<\/li>\n<li>\u914d\u7f6e\u5b89\u5168\u7684 3 \u6761\u7ea2\u7ebf<\/li>\n<li>viper \u843d\u5730 &#043; \u4e09\u4e2a\u771f\u5b9e\u7684\u5751<\/li>\n<\/ul>\n<\/li>\n<li>\u516b\u30018 \u4e2a\u9762\u8bd5\u8ffd\u95ee<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u4e00\u3001\u5148\u770b\u7ed3\u8bba&#xff1a;25 \u4e2a\u76ee\u5f55&#xff0c;\u6211\u4eec\u53ea\u7559\u4e86 9 \u4e2a<\/h3>\n<p>\u5148\u628a\u6211\u8ba4\u4e3a\u6700\u5bb9\u6613\u88ab\u8bef\u4f20\u7684\u4e00\u4ef6\u4e8b\u8bf4\u6e05\u695a\u3002<\/p>\n<p>\u7f51\u4e0a\u6d41\u4f20\u7684 Go \u9879\u76ee\u76ee\u5f55\u7ed3\u6784&#xff08;golang-standards\/project-layout&#xff09;\u6709 25 \u4e2a\u9876\u5c42\u76ee\u5f55&#xff0c;\u5f88\u591a\u4eba\u4ee5\u4e3a\u8fd9\u662f&#034;\u6807\u51c6&#034;\u3002\u5b83\u4e0d\u662f\u3002\u90a3\u4e2a\u4ed3\u5e93\u81ea\u5df1\u7b2c\u4e00\u53e5\u5c31\u5199\u7740\u8fd9\u4e0d\u662f\u5b98\u65b9\u6807\u51c6&#xff0c;Go \u5b98\u65b9\u4ece\u6765\u6ca1\u89c4\u5b9a\u8fc7\u76ee\u5f55\u7ed3\u6784\u3002<\/p>\n<p>\u6211\u628a\u90a3 25 \u4e2a\u76ee\u5f55\u9010\u4e2a\u8fc7\u4e86\u4e00\u904d&#xff0c;\u6309&#034;\u6211\u4eec\u56e2\u961f\u5b9e\u9645\u7559\u6ca1\u7559&#034;\u5206\u4e86\u4e09\u6863&#xff1a;<\/p>\n<table>\n<tr>\u76ee\u5f55\u4f5c\u7528\u6211\u4eec\u7684\u53d6\u820d\u7406\u7531<\/tr>\n<tbody>\n<tr>\n<td>cmd\/<\/td>\n<td>\u7a0b\u5e8f\u5165\u53e3&#xff0c;\u4e00\u4e2a\u5b50\u76ee\u5f55\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u591a\u5165\u53e3\u65f6\u65e0\u53ef\u66ff\u4ee3<\/td>\n<\/tr>\n<tr>\n<td>internal\/<\/td>\n<td>\u79c1\u6709\u4ee3\u7801&#xff0c;\u5916\u90e8\u65e0\u6cd5 import<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>Go \u7f16\u8bd1\u5668\u5f3a\u5236&#xff0c;\u4e0d\u662f\u7ea6\u5b9a<\/td>\n<\/tr>\n<tr>\n<td>pkg\/<\/td>\n<td>\u53ef\u88ab\u5916\u90e8\u5bfc\u5165\u7684\u516c\u5171\u5305<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>\u4e0d\u5bf9\u5916\u53d1\u5e93\u5c31\u522b\u5efa&#xff0c;\u5bb9\u6613\u53d8\u5783\u573e\u573a<\/td>\n<\/tr>\n<tr>\n<td>api\/<\/td>\n<td>\u63a5\u53e3\u5b9a\u4e49\u6587\u4ef6&#xff08;proto \/ OpenAPI&#xff09;<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u524d\u540e\u7aef\u5951\u7ea6\u7684\u552f\u4e00\u6765\u6e90<\/td>\n<\/tr>\n<tr>\n<td>configs\/<\/td>\n<td>\u914d\u7f6e\u6587\u4ef6\u6a21\u677f<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u914d\u4e0a example \u6587\u4ef6\u7ed9\u65b0\u4eba\u6284<\/td>\n<\/tr>\n<tr>\n<td>docs\/<\/td>\n<td>\u8bbe\u8ba1\u6587\u6863\u3001\u90e8\u7f72\u624b\u518c<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u51fa\u4e8b\u65f6\u7684\u6551\u547d\u8d44\u6599<\/td>\n<\/tr>\n<tr>\n<td>scripts\/<\/td>\n<td>\u6784\u5efa\u3001\u68c0\u67e5\u811a\u672c<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>Makefile \u91cc\u6bcf\u6761\u6307\u4ee4\u7684\u5b9e\u4f53<\/td>\n<\/tr>\n<tr>\n<td>Makefile<\/td>\n<td>\u7f16\u8bd1\u5165\u53e3<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u4e00\u6761 make build \u7edf\u4e00\u6240\u6709\u4eba<\/td>\n<\/tr>\n<tr>\n<td>go.mod<\/td>\n<td>\u6a21\u5757\u5b9a\u4e49<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u2014<\/td>\n<\/tr>\n<tr>\n<td>deployments\/<\/td>\n<td>K8s \/ compose \u7f16\u6392<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>\u6709 CI \u5e73\u53f0\u5c31\u4e0d\u7528\u624b\u5199\u6587\u4ef6\u5939\u5206\u5c42<\/td>\n<\/tr>\n<tr>\n<td>build\/<\/td>\n<td>Dockerfile\u3001\u6253\u5305\u4ea7\u7269<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>Dockerfile \u653e\u6839\u76ee\u5f55\u4e5f\u5b8c\u5168\u6ca1\u95ee\u9898<\/td>\n<\/tr>\n<tr>\n<td>test\/<\/td>\n<td>\u96c6\u6210\u6d4b\u8bd5<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>\u5355\u5143\u6d4b\u8bd5\u8ddf\u4ee3\u7801\u540c\u76ee\u5f55\u66f4\u597d<\/td>\n<\/tr>\n<tr>\n<td>web\/<\/td>\n<td>\u670d\u52a1\u7aef\u6a21\u677f\u3001SPA<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>\u7eaf API \u670d\u52a1\u76f4\u63a5\u5220<\/td>\n<\/tr>\n<tr>\n<td>assets\/<\/td>\n<td>\u524d\u7aef\u56fe\u7247\u3001CSS\u3001JS<\/td>\n<td>\u26a0\ufe0f \u6309\u9700<\/td>\n<td>\u540c\u4e0a&#xff0c;Go \u4ed3\u5e93\u4e0d\u8be5\u80cc\u524d\u7aef\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>website\/<\/td>\n<td>GitHub Pages \u7ad9\u70b9\u6570\u636e<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u4e00\u4e2a\u670d\u52a1\u4e0d\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td>examples\/<\/td>\n<td>\u793a\u4f8b\u4ee3\u7801<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u6709\u6587\u6863\u5c31\u591f\u4e86<\/td>\n<\/tr>\n<tr>\n<td>init\/<\/td>\n<td>systemd \/ supervisord \u914d\u7f6e<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u5bb9\u5668\u65f6\u4ee3\u4e0d\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td>third_party\/<\/td>\n<td>\u9b54\u6539\u7684\u7b2c\u4e09\u65b9\u6e90\u7801<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u771f\u9b54\u6539\u5c31 fork \u81ea\u5df1\u7684\u4ed3\u5e93<\/td>\n<\/tr>\n<tr>\n<td>tools\/<\/td>\n<td>\u9879\u76ee\u5de5\u5177<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u548c scripts\/\u3001pkg\/ \u91cd\u590d<\/td>\n<\/tr>\n<tr>\n<td>vendor\/<\/td>\n<td>\u4f9d\u8d56\u6e90\u7801\u526f\u672c<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u89c1\u7b2c\u4e8c\u8282<\/td>\n<\/tr>\n<tr>\n<td>ci\/<\/td>\n<td>\u6301\u7eed\u96c6\u6210\u6587\u4ef6<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u73b0\u5728\u90fd\u5728 .github\/workflows<\/td>\n<\/tr>\n<tr>\n<td>githooks\/<\/td>\n<td>Git \u94a9\u5b50<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u7528 .githooks \u6216 husky<\/td>\n<\/tr>\n<tr>\n<td>changelogs\/<\/td>\n<td>\u53d8\u66f4\u65e5\u5fd7<\/td>\n<td>\u274c \u5220<\/td>\n<td>\u7528 release notes<\/td>\n<\/tr>\n<tr>\n<td>benchmark\/<\/td>\n<td>\u57fa\u51c6\u6d4b\u8bd5<\/td>\n<td>\u274c \u5220<\/td>\n<td>_test.go \u91cc\u5c31\u80fd\u5199<\/td>\n<\/tr>\n<tr>\n<td>configs \u4e0b\u7684 _example<\/td>\n<td>\u914d\u7f6e\u793a\u4f8b<\/td>\n<td>\u2705 \u5fc5\u7559<\/td>\n<td>\u522b\u628a\u771f\u5b9e\u914d\u7f6e\u63d0\u4ea4\u4e0a\u53bb<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>9 \u4e2a\u5fc5\u7559\u30016 \u4e2a\u6309\u9700\u300110 \u4e2a\u5220\u6389&#xff0c;\u8fd9\u5c31\u662f\u6211\u4eec\u73b0\u5728\u7684\u5f62\u72b6\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u5220\u8fd9\u4e48\u72e0&#xff1f;\u4e0d\u662f\u6d01\u7656&#xff0c;\u662f\u88ab\u955c\u50cf\u4f53\u79ef\u5751\u8fc7\u3002<\/p>\n<p>\u53bb\u5e74\u4e00\u4e2a Go \u670d\u52a1\u4e0a\u7ebf&#xff0c;\u955c\u50cf\u63a8\u4e0a\u53bb 1.2G\u3002\u67e5\u4e86\u534a\u5929&#xff0c;\u539f\u56e0\u662f\u4ed3\u5e93\u91cc\u585e\u4e86 web\/ \u548c assets\/ \u4e24\u4e2a\u76ee\u5f55&#xff08;\u52a0\u8d77\u6765 900M \u7684 node_modules \u548c\u6784\u5efa\u4ea7\u7269&#xff09;&#xff0c;Dockerfile \u91cc\u5199\u7684\u662f COPY . .&#xff0c;\u5168\u6253\u8fdb\u955c\u50cf\u4e86\u3002\u672c\u6765\u8fd9\u4e2a\u670d\u52a1\u7684\u955c\u50cf\u5e94\u8be5\u662f 80M\u3002<\/p>\n<p>\u540e\u6765\u6539\u4e86\u4e24\u4ef6\u4e8b&#xff1a;\u4e00\u662f\u5220\u6389\u8fd9\u4e24\u4e2a\u76ee\u5f55&#xff08;\u524d\u7aef\u72ec\u7acb\u4ed3\u5e93&#xff09;&#xff0c;\u4e8c\u662f Dockerfile \u7528\u767d\u540d\u5355 COPY\u3002\u955c\u50cf\u56de\u5230 76M&#xff0c;\u51b7\u542f\u52a8\u4ece 40 \u79d2\u964d\u5230 6 \u79d2\u3002<\/p>\n<p>\u7a7a\u76ee\u5f55\u662f\u8d1f\u503a&#xff0c;\u4e0d\u662f\u8d44\u4ea7\u3002 \u4e00\u4e2a\u65b0\u4eba\u770b\u5230 25 \u4e2a\u76ee\u5f55&#xff0c;\u7b2c\u4e00\u53cd\u5e94\u6c38\u8fdc\u662f&#034;\u6211\u8be5\u5f80\u54ea\u653e&#034;&#xff0c;\u7136\u540e\u968f\u624b\u6311\u4e00\u4e2a&#xff0c;\u4e09\u4e2a\u6708\u540e\u540c\u4e00\u4e2a\u529f\u80fd\u6563\u843d\u5728\u4e09\u4e2a\u76ee\u5f55\u91cc\u3002<\/p>\n<h4>\u6211\u4eec\u73b0\u5728\u7684\u9aa8\u67b6<\/h4>\n<p>.<br \/>\n\u251c\u2500\u2500 api\/                    # \u63a5\u53e3\u5951\u7ea6&#xff1a;OpenAPI yaml \/ proto<br \/>\n\u251c\u2500\u2500 cmd\/<br \/>\n\u2502   \u251c\u2500\u2500 api-server\/         # \u5bf9\u5916 HTTP \u670d\u52a1\u5165\u53e3<br \/>\n\u2502   \u2514\u2500\u2500 worker\/             # \u5f02\u6b65\u4efb\u52a1\u6d88\u8d39\u8005\u5165\u53e3<br \/>\n\u251c\u2500\u2500 configs\/<br \/>\n\u2502   \u251c\u2500\u2500 config.yaml         # \u9ed8\u8ba4\u914d\u7f6e&#xff08;\u4e0d\u542b\u654f\u611f\u503c&#xff09;<br \/>\n\u2502   \u2514\u2500\u2500 config.example.yaml # \u7ed9\u65b0\u4eba\u6284\u7684\u6a21\u677f<br \/>\n\u251c\u2500\u2500 docs\/<br \/>\n\u2502   \u251c\u2500\u2500 design\/             # \u8bbe\u8ba1\u6587\u6863<br \/>\n\u2502   \u2514\u2500\u2500 runbook.md          # \u6392\u969c\u624b\u518c<br \/>\n\u251c\u2500\u2500 internal\/<br \/>\n\u2502   \u251c\u2500\u2500 handler\/            # HTTP \u5c42&#xff1a;\u53c2\u6570\u6821\u9a8c\u3001\u7ec4\u88c5\u54cd\u5e94<br \/>\n\u2502   \u251c\u2500\u2500 service\/            # \u4e1a\u52a1\u5c42&#xff1a;\u4e8b\u52a1\u8fb9\u754c\u5728\u8fd9\u91cc<br \/>\n\u2502   \u251c\u2500\u2500 repository\/         # \u5b58\u50a8\u5c42&#xff1a;\u53ea\u78b0 DB \u548c\u7f13\u5b58<br \/>\n\u2502   \u251c\u2500\u2500 model\/              # \u9886\u57df\u5bf9\u8c61<br \/>\n\u2502   \u2514\u2500\u2500 pkg\/                # \u9879\u76ee\u5185\u590d\u7528\u4f46\u4e0d\u662f\u4e1a\u52a1\u7684\u4e1c\u897f<br \/>\n\u251c\u2500\u2500 pkg\/                    # \u660e\u786e\u6253\u7b97\u7ed9\u522b\u7684\u9879\u76ee\u7528\u7684<br \/>\n\u251c\u2500\u2500 scripts\/<br \/>\n\u2502   \u251c\u2500\u2500 build.sh<br \/>\n\u2502   \u2514\u2500\u2500 lint.sh<br \/>\n\u251c\u2500\u2500 Makefile<br \/>\n\u2514\u2500\u2500 go.mod<\/p>\n<p>\u6bcf\u4e2a\u76ee\u5f55\u4e00\u53e5\u8bdd\u804c\u8d23&#xff0c;\u65b0\u4eba\u4e00\u770b\u5c31\u77e5\u9053\u4ee3\u7801\u5f80\u54ea\u653e&#xff1a;<\/p>\n<ul>\n<li>api\/ \u2014\u2014 \u53ea\u653e\u5951\u7ea6&#xff0c;\u4e0d\u653e\u5b9e\u73b0<\/li>\n<li>cmd\/ \u2014\u2014 \u53ea\u505a\u88c5\u914d&#xff1a;\u8bfb\u914d\u7f6e\u3001\u8fde\u4f9d\u8d56\u3001\u6ce8\u518c\u8def\u7531\u3001\u542f\u52a8\u3001\u4f18\u96c5\u9000\u51fa&#xff0c;\u4e00\u884c\u4e1a\u52a1\u903b\u8f91\u90fd\u6ca1\u6709<\/li>\n<li>internal\/handler \u2014\u2014 \u53ea\u505a HTTP \u8f6c\u6362&#xff0c;\u4e0d\u5199 if-else \u4e1a\u52a1\u5224\u65ad<\/li>\n<li>internal\/service \u2014\u2014 \u4e1a\u52a1\u89c4\u5219&#xff0c;\u4e8b\u52a1\u8fb9\u754c<\/li>\n<li>internal\/repository \u2014\u2014 SQL \u548c Redis \u547d\u4ee4&#xff0c;\u53ea\u5728\u8fd9\u5c42\u51fa\u73b0<\/li>\n<li>pkg\/ \u2014\u2014 \u53ea\u6709\u5728&#034;\u786e\u5b9a\u522b\u7684\u9879\u76ee\u8981\u7528&#034;\u65f6\u624d\u5efa<\/li>\n<\/ul>\n<p>\u60f3\u5148\u7cfb\u7edf\u8fc7\u4e00\u904d Go \u7684\u77e5\u8bc6\u5730\u56fe&#xff0c;\u6211\u5728\u300a\u65b0\u7c89\u5fc5\u770b\u300b\u91cc\u6309\u56db\u677f\u5757\u6392\u597d\u4e86\u987a\u5e8f&#xff0c;\u53ef\u4ee5\u5bf9\u7167\u7740\u770b&#xff1a;Go \u540e\u7aef &#043; Agent\/RAG \u5b66\u4e60\u8def\u7ebf\u3002<\/p>\n<h3>\u4e8c\u3001\/internal\u3001\/cmd\u3001\/vendor \u4e09\u4e2a\u5fc5\u987b\u8bb2\u6e05\u7684<\/h3>\n<p>\u8fd9\u4e09\u4e2a\u76ee\u5f55\u51e0\u4e4e\u6240\u6709\u9762\u8bd5\u90fd\u4f1a\u95ee&#xff0c;\u4f46\u7b54\u5bf9\u7684\u4e0d\u5230\u4e00\u534a\u3002<\/p>\n<h4>\/internal \u4e0d\u662f\u7ea6\u5b9a&#xff0c;\u662f\u7f16\u8bd1\u5668\u5f3a\u5236\u7684<\/h4>\n<p>\u5f88\u591a\u4eba\u4ee5\u4e3a internal \u53ea\u662f\u4e2a\u547d\u540d\u4e60\u60ef&#xff0c;\u56e2\u961f\u81ea\u89c9\u9075\u5b88\u3002\u4e0d\u662f\u3002go build \u4f1a\u76f4\u63a5\u62d2\u7edd\u3002<\/p>\n<p>Go \u7684\u89c4\u5219\u662f&#xff1a;\u4efb\u4f55\u5bfc\u5165\u8def\u5f84\u91cc\u5305\u542b internal \u7684\u5305&#xff0c;\u53ea\u80fd\u88ab internal \u7684\u7236\u76ee\u5f55\u6811\u5185\u7684\u5305\u5bfc\u5165\u3002<\/p>\n<p>\u6211\u4eec\u62ff\u771f\u5b9e\u4ee3\u7801\u9a8c\u8bc1\u4e00\u4e0b\u3002\u5047\u8bbe\u9879\u76ee\u7ed3\u6784&#xff1a;<\/p>\n<p>myapp\/<br \/>\n\u251c\u2500\u2500 internal\/<br \/>\n\u2502   \u2514\u2500\u2500 auth\/token.go     # package auth<br \/>\n\u2514\u2500\u2500 main.go                # package main&#xff0c;\u540c\u7ea7&#xff0c;\u80fd\u5bfc\u5165<br \/>\nother\/<br \/>\n\u2514\u2500\u2500 x\/main.go              # \u5916\u90e8\u9879\u76ee&#xff0c;\u5bfc\u5165\u5c31\u62a5\u9519<\/p>\n<p>\u5728 myapp\/main.go \u91cc\u5199 import &#034;myapp\/internal\/auth&#034;&#xff0c;\u7f16\u8bd1\u901a\u8fc7\u3002\u6362\u4e2a\u5916\u90e8\u6a21\u5757\u5199\u540c\u6837\u7684 import&#xff0c;go build \u76f4\u63a5\u7ed9\u4f60&#xff1a;<\/p>\n<p>use of internal package myapp\/internal\/auth not allowed<\/p>\n<p>\u8fd9\u6761\u62a5\u9519\u662f\u7f16\u8bd1\u5668\u629b\u7684&#xff0c;\u4e0d\u662f\u4f60 CI \u91cc\u914d\u7684 lint\u3002<\/p>\n<p>\u8fd9\u4e2a\u673a\u5236\u89e3\u51b3\u4e24\u4e2a\u771f\u5b9e\u95ee\u9898&#xff1a;<\/p>\n<p>\u7b2c\u4e00&#xff0c;\u628a\u8fd0\u8425\u540e\u53f0\u7684\u4ee3\u7801\u548c C \u7aef\u4ee3\u7801\u9694\u79bb\u5f00\u3002 \u6211\u4eec\u4e4b\u524d\u6709\u4e2a\u670d\u52a1&#xff0c;\u8fd0\u8425\u7ba1\u7406\u63a5\u53e3\u548c\u7528\u6237\u63a5\u53e3\u5728\u540c\u4e00\u4e2a\u5305\u91cc&#xff0c;\u67d0\u4e2a UpdateBalance \u51fd\u6570\u88ab C \u7aef\u8bef\u5f15\u7528&#xff0c;\u4e0a\u7ebf\u540e\u7528\u6237\u80fd\u76f4\u63a5\u6539\u81ea\u5df1\u7684\u4f59\u989d\u3002\u52a0 internal \u4e4b\u540e\u8fd9\u79cd\u8bef\u5f15\u7528\u5728\u7f16\u8bd1\u671f\u5c31\u6302\u4e86\u3002<\/p>\n<p>\u7b2c\u4e8c&#xff0c;\u675c\u7edd&#034;\u968f\u624b\u5bfc\u5165&#034;\u3002 \u6709\u4e9b\u5305\u4f60\u5199\u51fa\u6765\u5c31\u662f\u7ed9\u5185\u90e8\u7528\u7684&#xff0c;\u6bd4\u5982\u67d0\u4e2a\u5e26\u7f13\u5b58\u7684\u67e5\u8be2\u5c01\u88c5\u3001\u67d0\u4e2a\u53ea\u80fd\u5355\u4f8b\u7684\u8fde\u63a5\u6c60\u3002\u653e internal \u4e0b&#xff0c;\u522b\u4eba\u60f3\u7528\u5c31\u5f97\u5148\u590d\u5236\u2014\u2014\u590d\u5236\u8fd9\u4e2a\u52a8\u4f5c\u672c\u8eab\u5c31\u662f\u4e00\u9053\u601d\u8003\u95e8\u69db\u3002<\/p>\n<p>\u5bf9\u5e94\u5730&#xff0c;pkg\/ \u662f\u53cd\u8fc7\u6765&#xff1a;\u4f60\u660e\u786e\u5e0c\u671b\u88ab\u5916\u90e8\u5bfc\u5165\u7684\u4e1c\u897f\u624d\u653e\u8fd9\u91cc\u3002\u5982\u679c\u4e00\u4e2a\u9879\u76ee\u6ca1\u6709\u5bf9\u5916\u53d1 SDK \u7684\u6253\u7b97&#xff0c;pkg\/ \u53ef\u4ee5\u4e0d\u5efa\u2014\u2014\u5efa\u4e86\u4e5f\u53ea\u4f1a\u53d8\u6210&#034;\u4e0d\u77e5\u9053\u653e\u54ea\u7684\u4ee3\u7801\u4e34\u65f6\u4ed3\u5e93&#034;\u3002<\/p>\n<h4>\/cmd \u7684\u4e09\u6761\u7eaa\u5f8b<\/h4>\n<li>\u53ea\u505a\u88c5\u914d&#xff0c;\u4e0d\u653e\u4e1a\u52a1\u903b\u8f91\u3002 cmd\/api-server\/main.go \u91cc\u5e94\u8be5\u662f\u8bfb\u914d\u7f6e \u2192 \u521d\u59cb\u5316 DB\/Redis \u2192 \u6ce8\u518c\u8def\u7531 \u2192 \u542f\u52a8 \u2192 \u7b49\u4fe1\u53f7\u4f18\u96c5\u9000\u51fa\u3002<\/li>\n<li>\u5b50\u76ee\u5f55\u540d &#061; \u7f16\u8bd1\u51fa\u6765\u7684\u53ef\u6267\u884c\u6587\u4ef6\u540d\u3002 cmd\/api-server\/ \u7f16\u51fa\u6765\u5c31\u662f api-server&#xff0c;\u522b\u53eb cmd\/server1\u3002<\/li>\n<li>\u4e00\u4e2a\u5b50\u76ee\u5f55\u4e00\u4e2a\u8fdb\u7a0b\u3002 cmd\/api-server\u3001cmd\/worker\u3001cmd\/migrate \u662f\u4e09\u4e2a\u72ec\u7acb\u4e8c\u8fdb\u5236&#xff0c;\u5171\u7528 internal\/\u3002\u8fd9\u6837 worker \u6269\u5bb9\u65f6\u4e0d\u7528\u628a HTTP \u670d\u52a1\u4e5f\u590d\u5236\u4e00\u4efd\u3002<\/li>\n<h4>\/vendor \u4ec0\u4e48\u65f6\u5019\u8be5\u7528&#xff0c;\u4ec0\u4e48\u65f6\u5019\u7edd\u5bf9\u522b\u7528<\/h4>\n<p>\u5148\u8bf4\u4e00\u4e2a\u4f60\u7ed9\u7684\u7d20\u6750\u91cc&#xff08;\u4e5f\u662f\u5f88\u591a\u535a\u5ba2\u91cc&#xff09;\u7684\u7b14\u8bef&#xff1a;\u751f\u6210 vendor \u76ee\u5f55\u7684\u547d\u4ee4\u662f go mod vendor&#xff0c;\u4e0d\u662f go vendor\u3002<\/p>\n<p>vendor \u662f\u628a\u4f9d\u8d56\u6e90\u7801\u590d\u5236\u4e00\u4efd\u8fdb\u4f60\u7684\u4ed3\u5e93\u3002\u5b83\u6362\u6765\u7684\u662f&#xff1a;\u6784\u5efa\u65f6\u4e0d\u8054\u7f51\u3001\u4f9d\u8d56\u7248\u672c\u5b8c\u5168\u9501\u5b9a\u3001\u53ef\u5ba1\u8ba1&#xff08;\u5b89\u5168\u56e2\u961f\u80fd\u76f4\u63a5\u7ffb\u6e90\u7801&#xff09;\u3002<\/p>\n<p>\u4ee3\u4ef7\u4e5f\u5f88\u76f4\u63a5&#xff1a;\u4ed3\u5e93\u81a8\u80c0&#xff08;\u4e00\u4e2a\u4e2d\u7b49\u670d\u52a1\u5927\u6982\u591a 30-80M&#xff09;\u3001\u5347\u7ea7\u4f9d\u8d56\u65f6 diff \u7206\u70b8\u3001code review \u566a\u97f3\u5de8\u5927\u3002<\/p>\n<p>\u6211\u7684\u5224\u65ad\u6807\u51c6&#xff1a;<\/p>\n<ul>\n<li>\u8981\u4ea4\u4ed8\u5230\u5ba2\u6237\u5185\u7f51\u3001\u6216\u8005\u6709\u5408\u89c4\u5ba1\u8ba1\u8981\u6c42 \u2192 \u7528 vendor<\/li>\n<li>\u666e\u901a\u5fae\u670d\u52a1&#xff0c;CI \u80fd\u8054\u7f51\u62c9 module \u2192 \u4e0d\u7528&#xff0c;\u9760 go.sum \u9501\u7248\u672c\u5c31\u591f\u4e86<\/li>\n<li>\u5199\u7ed9\u522b\u4eba\u7528\u7684\u5e93 \u2192 \u7edd\u5bf9\u4e0d\u7528&#xff0c;\u7528\u5e93\u7684\u4eba\u4f1a\u88ab\u4f60\u7684 vendor \u6076\u5fc3\u5230<\/li>\n<\/ul>\n<h3>\u4e09\u3001API \u8bbe\u8ba1&#xff1a;5 \u6761\u786c\u89c4\u5219\u548c 3 \u4e2a\u53cd\u4f8b<\/h3>\n<p>RESTful \u8c01\u90fd\u4f1a\u8bf4\u4e24\u53e5&#xff0c;\u4f46\u771f\u5230\u5b9a\u63a5\u53e3\u7684\u65f6\u5019&#xff0c;\u6700\u5e38\u89c1\u7684\u8fd8\u662f&#034;\u6bcf\u4e2a\u63a5\u53e3\u4e00\u4e2a\u52a8\u8bcd&#034;\u3002<\/p>\n<p>5 \u6761\u89c4\u5219&#xff0c;\u6211\u6309\u6700\u5bb9\u6613\u8e29\u7684\u987a\u5e8f\u6392&#xff1a;<\/p>\n<p>\u89c4\u5219 1&#xff1a;\u8d44\u6e90\u540d\u7528\u540d\u8bcd&#xff0c;\u4e14\u7528\u590d\u6570\u3002<\/p>\n<table>\n<tr>\u9519\u8bef\u5199\u6cd5\u6b63\u786e\u5199\u6cd5<\/tr>\n<tbody>\n<tr>\n<td>GET \/api\/getUserList<\/td>\n<td>GET \/api\/v1\/users<\/td>\n<\/tr>\n<tr>\n<td>POST \/api\/createOrder<\/td>\n<td>POST \/api\/v1\/orders<\/td>\n<\/tr>\n<tr>\n<td>POST \/api\/deleteUser<\/td>\n<td>DELETE \/api\/v1\/users\/123<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u590d\u6570\u4e0d\u662f\u5f3a\u8feb\u75c7\u3002\/users \u5929\u7136\u8868\u8fbe&#034;\u8fd9\u662f\u4e00\u4e2a\u96c6\u5408&#034;&#xff0c;\/users\/123 \u5c31\u662f\u96c6\u5408\u91cc\u7684\u4e00\u4e2a\u5143\u7d20&#xff0c;\u5c42\u7ea7\u5173\u7cfb\u4e0d\u7528\u53e6\u5916\u89e3\u91ca\u3002<\/p>\n<p>\u89c4\u5219 2&#xff1a;\u80fd\u53d8\u6210\u8d44\u6e90\u5c5e\u6027\u6216 HTTP \u65b9\u6cd5\u7684&#xff0c;\u4e0d\u8981\u65b0\u589e\u8def\u5f84\u3002<\/p>\n<ul>\n<li>\u60f3\u6539\u72b6\u6001 \u2192 \u7528 PATCH \/orders\/123 &#043; body \u91cc\u5e26 {&#034;status&#034;:&#034;paid&#034;}<\/li>\n<li>\u60f3\u505a&#034;\u9876\u7f6e\u7528\u6237&#034; \u2192 \u4e0d\u8981 \/users\/123\/top&#xff0c;\u6539\u6210 PATCH \/users\/123 {&#034;pinned&#034;:true}<\/li>\n<\/ul>\n<p>\u5224\u65ad\u529e\u6cd5&#xff1a;\u5982\u679c\u8fd9\u4e2a\u64cd\u4f5c\u7684\u7ed3\u679c\u662f&#034;\u67d0\u4e2a\u8d44\u6e90\u7684\u4e00\u4e2a\u5b57\u6bb5\u53d8\u4e86&#034;&#xff0c;\u90a3\u5b83\u5c31\u662f\u4e00\u6b21\u8d44\u6e90\u4fee\u6539\u3002<\/p>\n<p>\u89c4\u5219 3&#xff1a;URL \u7528\u5c0f\u5199\u5b57\u6bcd &#043; \u4e2d\u6a2a\u7ebf&#xff0c;\u7248\u672c\u53f7\u9664\u5916\u3002<\/p>\n<p>\/api\/v1\/order-items \u5bf9&#xff0c;\/api\/v1\/orderItems\u3001\/api\/v1\/Order_Items \u90fd\u4e0d\u5bf9\u3002\u5927\u5c0f\u5199\u6df7\u7528\u5728\u67d0\u4e9b\u4ee3\u7406\u548c Nginx \u89c4\u5219\u4e0b\u4f1a\u88ab\u6539\u5199&#xff0c;\u7ebf\u4e0a\u4f1a\u83ab\u540d\u5176\u5999 404\u3002<\/p>\n<p>\u89c4\u5219 4&#xff1a;URL \u5c42\u7ea7\u4e0d\u8d85\u8fc7\u4e24\u5c42&#xff0c;\u66f4\u6df1\u7684\u7528\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<p>\/api\/v1\/users\/123\/orders\/456\/items \u8fd9\u79cd\u5c31\u522b\u5199\u4e86\u3002\u6539\u6210 \/api\/v1\/order-items?order_id&#061;456\u3002\u539f\u56e0\u5f88\u5b9e\u9645&#xff1a;\u5c42\u7ea7\u4e00\u6df1&#xff0c;\u6743\u9650\u6821\u9a8c\u5c31\u8981\u4e00\u5c42\u5c42\u5f80\u4e0a\u67e5&#xff0c;\u4ee3\u7801\u548c\u6027\u80fd\u53cc\u8f93\u3002<\/p>\n<p>\u89c4\u5219 5&#xff1a;\u6279\u91cf\u5220\u9664\u4e0d\u8981\u53d1\u660e\u65b0\u52a8\u8bcd\u3002<\/p>\n<p>\u4e24\u4e2a\u65b9\u6848\u90fd\u80fd\u8fc7&#xff1a;<\/p>\n<ul>\n<li>POST \/api\/v1\/users\/batch-delete &#043; body {&#034;ids&#034;:[1,2,3]}&#xff08;\u8868\u8fbe\u6e05\u6670&#xff0c;\u4f46\u5f15\u5165\u4e86\u52a8\u8bcd&#xff09;<\/li>\n<li>DELETE \/api\/v1\/users?ids&#061;1,2,3&#xff08;\u66f4 REST&#xff0c;\u4f46 URL \u957f\u5ea6\u53d7\u7f51\u5173\u9650\u5236&#xff0c;\u51e0\u767e\u4e2a id \u4f1a\u88ab\u622a\u65ad&#xff09;<\/li>\n<\/ul>\n<p>\u6211\u4eec\u7ebf\u4e0a\u7528\u7b2c\u4e00\u79cd\u3002\u7406\u7531\u662f ids \u53ef\u80fd\u6709\u51e0\u767e\u4e2a&#xff0c;\u585e query \u91cc\u4f1a\u88ab 414 \u6389\u3002<\/p>\n<p>\u7248\u672c\u53f7\u653e\u54ea\u91cc&#xff1f; \/api\/v1\/ \u524d\u7f00&#xff0c;\u4e0d\u8981\u7528 Header\u3002\u539f\u56e0\u5f88\u7b80\u5355&#xff1a;\u6d4f\u89c8\u5668\u5730\u5740\u680f\u3001Nginx \u65e5\u5fd7\u3001\u6293\u5305\u5de5\u5177\u3001\u7ed9\u5ba2\u670d\u770b\u7684\u94fe\u63a5&#xff0c;\u5168\u90fd\u80fd\u76f4\u63a5\u770b\u5230\u7248\u672c\u3002\u653e Header \u91cc\u6392\u67e5\u95ee\u9898\u65f6\u4f60\u4f1a\u60f3\u9a82\u4eba\u3002<\/p>\n<h3>\u56db\u3001\u5b89\u5168\u6027\u4e0e\u5e42\u7b49\u6027&#xff1a;\u90a3\u5f20\u8868\u683c\u80cc\u540e\u662f\u771f\u91d1\u767d\u94f6<\/h3>\n<p>\u4e24\u4e2a\u6982\u5ff5\u5148\u5206\u6e05&#xff1a;<\/p>\n<ul>\n<li>\u5b89\u5168\u6027&#xff08;safe&#xff09;&#xff1a;\u8fd9\u4e2a\u8bf7\u6c42\u4e0d\u6539\u53d8\u8d44\u6e90\u72b6\u6001\u3002GET \u662f\u5b89\u5168\u7684&#xff0c;\u4f60\u53ef\u80fd\u88ab CDN \u7f13\u5b58\u3001\u88ab\u722c\u866b\u72c2\u5237&#xff0c;\u90fd\u6ca1\u6709\u526f\u4f5c\u7528\u3002<\/li>\n<li>\u5e42\u7b49\u6027&#xff08;idempotent&#xff09;&#xff1a;\u540c\u4e00\u4e2a\u8bf7\u6c42\u6267\u884c\u4e00\u6b21\u548c\u6267\u884c N \u6b21&#xff0c;\u5bf9\u8d44\u6e90\u7684\u7ed3\u679c\u4e00\u6837\u3002<\/li>\n<\/ul>\n<table>\n<tr>\u65b9\u6cd5\u5b89\u5168\u6027\u5e42\u7b49\u6027<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">POST<\/td>\n<td align=\"center\">\u5426<\/td>\n<td align=\"center\">\u5426<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">GET<\/td>\n<td align=\"center\">\u662f<\/td>\n<td align=\"center\">\u662f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">DELETE<\/td>\n<td align=\"center\">\u5426<\/td>\n<td align=\"center\">\u662f<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">PUT<\/td>\n<td align=\"center\">\u5426<\/td>\n<td align=\"center\">\u662f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f88\u591a\u4eba\u5361\u5728&#034;DELETE \u4e0d\u6539\u53d8\u72b6\u6001\u5374\u5e42\u7b49&#034;\u3002\u5e42\u7b49\u8bf4\u7684\u4e0d\u662f&#034;\u72b6\u6001\u6ca1\u53d8&#034;&#xff0c;\u800c\u662f&#034;\u6700\u7ec8\u72b6\u6001\u4e00\u81f4&#034;\u3002DELETE \/users\/123 \u7b2c\u4e00\u6b21\u5220\u6389\u4e86&#xff0c;\u7b2c\u4e8c\u6b21\u8fd4\u56de 404&#xff0c;\u4f46\u8d44\u6e90\u6700\u7ec8\u72b6\u6001\u90fd\u662f&#034;\u4e0d\u5b58\u5728&#034;&#xff0c;\u6240\u4ee5\u5e42\u7b49\u3002<\/p>\n<p>PUT \u540c\u7406&#xff1a;PUT \/users\/123 {&#034;name&#034;:&#034;xu&#034;} \u8c03\u5341\u6b21&#xff0c;\u5e93\u91cc\u5c31\u662f name&#061;xu&#xff0c;\u4e0d\u4f1a\u53d8\u6210\u5341\u4e2a xu\u3002<\/p>\n<p>POST \u4e0d\u5e42\u7b49&#xff0c;\u8fd9\u662f\u8981\u547d\u7684\u5730\u65b9\u3002<\/p>\n<p>\u6211\u4eec\u8e29\u8fc7\u7684\u5751&#xff1a;\u652f\u4ed8\u6e20\u9053\u56de\u8c03\u6211\u4eec\u7684 POST \/api\/v1\/payments\/notify&#xff0c;\u6e20\u9053\u65b9\u56e0\u4e3a\u7f51\u7edc\u8d85\u65f6\u91cd\u8bd5\u4e86 4 \u6b21\u3002\u6211\u4eec\u7684\u5b9e\u73b0\u662f&#034;\u6536\u5230\u56de\u8c03\u5c31\u52a0\u4e00\u6b21\u8d26&#034;&#xff0c;\u7ed3\u679c\u7528\u6237\u5145\u4e86 100&#xff0c;\u8d26\u4e0a\u591a\u4e86 400\u3002<\/p>\n<p>\u4fee\u590d\u4e0d\u662f&#034;\u8ba9\u6e20\u9053\u522b\u91cd\u8bd5&#034;&#xff08;\u4f60\u63a7\u5236\u4e0d\u4e86&#xff09;&#xff0c;\u800c\u662f\u8ba9 POST \u53d8\u6210\u5e42\u7b49\u3002\u6807\u51c6\u505a\u6cd5\u662f\u5e42\u7b49\u952e&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ internal\/service\/payment.go<\/span><br \/>\n<span class=\"token keyword\">func<\/span> <span class=\"token punctuation\">(<\/span>s <span class=\"token operator\">*<\/span>PaymentService<span class=\"token punctuation\">)<\/span> <span class=\"token function\">HandleNotify<\/span><span class=\"token punctuation\">(<\/span>ctx context<span class=\"token punctuation\">.<\/span>Context<span class=\"token punctuation\">,<\/span> req <span class=\"token operator\">*<\/span>NotifyReq<span class=\"token punctuation\">)<\/span> <span class=\"token builtin\">error<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5e42\u7b49\u952e&#xff1a;\u6e20\u9053\u6d41\u6c34\u53f7 &#043; \u4e8b\u4ef6\u7c7b\u578b&#xff0c;\u5929\u7136\u552f\u4e00<\/span><br \/>\n    key <span class=\"token operator\">:&#061;<\/span> fmt<span class=\"token punctuation\">.<\/span><span class=\"token function\">Sprintf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;pay:notify:%s:%s&#034;<\/span><span class=\"token punctuation\">,<\/span> req<span class=\"token punctuation\">.<\/span>ChannelTradeNo<span class=\"token punctuation\">,<\/span> req<span class=\"token punctuation\">.<\/span>EventType<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ SETNX&#xff1a;\u53ea\u6709\u7b2c\u4e00\u6b21\u80fd\u6210\u529f&#xff0c;TTL \u8986\u76d6\u6e20\u9053\u7684\u6700\u957f\u91cd\u8bd5\u7a97\u53e3&#xff08;24h&#xff09;<\/span><br \/>\n    ok<span class=\"token punctuation\">,<\/span> err <span class=\"token operator\">:&#061;<\/span> s<span class=\"token punctuation\">.<\/span>redis<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetNX<\/span><span class=\"token punctuation\">(<\/span>ctx<span class=\"token punctuation\">,<\/span> key<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;1&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">24<\/span><span class=\"token operator\">*<\/span>time<span class=\"token punctuation\">.<\/span>Hour<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">Result<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> err <span class=\"token operator\">!&#061;<\/span> <span class=\"token boolean\">nil<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> fmt<span class=\"token punctuation\">.<\/span><span class=\"token function\">Errorf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;redis setnx: %w&#034;<\/span><span class=\"token punctuation\">,<\/span> err<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token operator\">!<\/span>ok <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u91cd\u590d\u56de\u8c03&#xff0c;\u76f4\u63a5\u8fd4\u56de\u6210\u529f&#xff0c;\u522b\u8ba9\u6e20\u9053\u7ee7\u7eed\u91cd\u8bd5<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">nil<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u8fd9\u91cc\u624d\u662f\u771f\u6b63\u7684\u4e1a\u52a1\u5904\u7406<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> s<span class=\"token punctuation\">.<\/span>repo<span class=\"token punctuation\">.<\/span><span class=\"token function\">UpdateBalance<\/span><span class=\"token punctuation\">(<\/span>ctx<span class=\"token punctuation\">,<\/span> req<span class=\"token punctuation\">.<\/span>UserID<span class=\"token punctuation\">,<\/span> req<span class=\"token punctuation\">.<\/span>Amount<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e09\u4e2a\u7ec6\u8282\u522b\u6f0f&#xff1a;<\/p>\n<li>\u5e42\u7b49\u952e\u8981\u7528&#034;\u4e1a\u52a1\u4e0a\u5929\u7136\u552f\u4e00&#034;\u7684\u4e1c\u897f&#xff0c;\u6bd4\u5982\u6e20\u9053\u6d41\u6c34\u53f7&#xff0c;\u4e0d\u8981\u7528\u65f6\u95f4\u6233\u6216 UUID\u2014\u2014\u90a3\u7b49\u4e8e\u6ca1\u505a\u5e42\u7b49\u3002<\/li>\n<li>TTL \u8981\u8986\u76d6\u5bf9\u65b9\u7684\u6700\u957f\u91cd\u8bd5\u7a97\u53e3&#xff0c;\u4e00\u822c\u662f 24 \u5c0f\u65f6\u3002TTL \u592a\u77ed\u4f1a\u5728\u7a97\u53e3\u5916\u91cd\u653e&#xff0c;\u592a\u957f\u4f1a\u5360\u5185\u5b58\u3002<\/li>\n<li>\u91cd\u590d\u8bf7\u6c42\u8981\u8fd4\u56de\u6210\u529f&#xff0c;\u4e0d\u80fd\u8fd4\u56de\u9519\u8bef\u3002\u8fd4\u56de\u9519\u8bef\u5bf9\u65b9\u4f1a\u7ee7\u7eed\u91cd\u8bd5&#xff0c;\u4f60\u53ea\u662f\u628a\u98ce\u66b4\u5ef6\u540e\u3002<\/li>\n<p>\u518d\u8865\u4e00\u53e5&#xff1a;SetNX \u6210\u529f\u540e\u5982\u679c\u4e1a\u52a1\u5904\u7406\u5931\u8d25&#xff0c;\u8bb0\u5f97\u628a key \u5220\u6389&#xff08;\u6216\u8005\u7528\u66f4\u4e25\u8c28\u7684&#034;\u9884\u5360 &#043; \u786e\u8ba4&#034;\u4e24\u6bb5\u5f0f&#xff09;&#xff0c;\u5426\u5219\u8fd9\u4e2a\u8ba2\u5355\u5c31\u6c38\u8fdc\u5361\u4f4f\u4e86\u3002\u8fd9\u662f\u53e6\u4e00\u4e2a\u5751&#xff0c;\u4e0b\u4e00\u7bc7\u8bb2\u5206\u5e03\u5f0f\u4e8b\u52a1\u65f6\u5c55\u5f00\u3002<\/p>\n<p>\u987a\u4fbf\u8bf4&#xff0c;\u8fd9\u6bb5\u4ee3\u7801\u91cc SetNX \u80fd\u7528&#xff0c;\u524d\u63d0\u662f\u4f60\u77e5\u9053 Redis \u5355\u547d\u4ee4\u7684\u539f\u5b50\u6027\u8fb9\u754c\u5728\u54ea\u3002\u5982\u679c\u4f60\u5bf9 atomic\u3001sync \u5e95\u5c42\u7684\u5b9e\u73b0\u8fd8\u4e0d\u719f&#xff0c;\u53ef\u4ee5\u5148\u770b\u8fd9\u7bc7&#xff1a;Go GMP \u8c03\u5ea6\u5668 10 \u4e2a\u9ad8\u9891\u8ffd\u95ee\u3002<\/p>\n<p>\u63a5\u53e3\u517c\u5bb9\u600e\u4e48\u529e&#xff1f; \u4e00\u53e5\u8bdd&#xff1a;\u9700\u8981\u6539\u903b\u8f91\u5c31\u65b0\u5efa\u63a5\u53e3&#xff0c;\u7528\u7248\u672c\u53f7\u533a\u5206&#xff08;\/v2\/&#xff09;\u3002\u4e0d\u8981\u5728\u539f\u63a5\u53e3\u4e0a\u5077\u5077\u6539\u8bed\u4e49\u2014\u2014\u4f60\u6c38\u8fdc\u4e0d\u77e5\u9053\u6709\u591a\u5c11\u8001\u5ba2\u6237\u7aef\u5728\u4f9d\u8d56\u65e7\u884c\u4e3a\u3002<\/p>\n<h3>\u4e94\u3001\u9519\u8bef\u7801&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5168\u5c40\u7edf\u4e00&#xff0c;\u516d\u6bb5\u7f16\u53f7\u600e\u4e48\u7b97<\/h3>\n<h4>\u4e3a\u4ec0\u4e48\u4e0d\u63a8\u8350\u5168\u5c40\u9519\u8bef\u7801<\/h4>\n<p>\u5168\u5c40\u9519\u8bef\u7801\u7684\u610f\u601d\u662f&#xff1a;\u6574\u4e2a\u516c\u53f8\u7ef4\u62a4\u4e00\u4e2a\u5927\u679a\u4e3e&#xff0c;10001 &#061; \u53c2\u6570\u9519\u8bef\u300110002 &#061; \u672a\u767b\u5f55\u300110003 &#061; \u4f59\u989d\u4e0d\u8db3\u2026\u2026<\/p>\n<p>\u4e09\u4e2a\u81f4\u547d\u95ee\u9898&#xff1a;<\/p>\n<li>\u679a\u4e3e\u51b2\u7a81\u3002 \u5341\u51e0\u4e2a\u56e2\u961f\u5f80\u540c\u4e00\u4e2a\u6587\u4ef6\u91cc\u52a0&#xff0c;\u4e09\u4e2a\u6708\u5fc5\u7136\u649e\u53f7\u3002\u649e\u53f7\u4e4b\u540e\u7ebf\u4e0a\u62a5 10002&#xff0c;\u4f60\u6839\u672c\u4e0d\u77e5\u9053\u662f\u54ea\u4e2a\u56e2\u961f\u5b9a\u4e49\u7684\u3002<\/li>\n<li>\u5b9a\u4f4d\u4e0d\u4e86\u6765\u6e90\u3002 \u9519\u8bef\u7801\u672c\u8eab\u4e0d\u5e26&#034;\u6211\u662f\u8c01&#034;&#xff0c;\u53ea\u80fd\u53cd\u67e5\u6587\u6863\u3002<\/li>\n<li>\u6ca1\u4eba\u6562\u5220\u3002 \u8c01\u4e5f\u4e0d\u77e5\u9053\u54ea\u4e2a\u7801\u8fd8\u6709\u6ca1\u6709\u5ba2\u6237\u7aef\u5728\u5224\u65ad&#xff0c;\u6700\u540e\u53d8\u6210\u4e00\u4e2a\u53ea\u589e\u4e0d\u51cf\u7684\u5783\u573e\u8868\u3002<\/li>\n<h4>\u6309\u9879\u76ee &#043; \u670d\u52a1 &#043; \u6a21\u5757 &#043; \u9519\u8bef\u7801\u56db\u7ea7\u7f16\u53f7<\/h4>\n<p>\u6211\u4eec\u7528\u7684\u683c\u5f0f\u662f 8 \u4f4d\u6570\u5b57&#xff0c;\u6bcf\u4e24\u4f4d\u4e00\u6bb5&#xff1a;<\/p>\n<p>06100325<br \/>\n\u2502\u2502\u2502\u2502\u2502\u2514\u2534\u2500 25   &#xff1a;\u5177\u4f53\u9519\u8bef\u7801&#xff08;\u6a21\u5757\u5185 00-99&#xff09;<br \/>\n\u2502\u2502\u2514\u2534\u2500\u2500\u2500 03   &#xff1a;\u6a21\u5757\u7f16\u53f7&#xff08;03 &#061; \u652f\u4ed8\u6a21\u5757&#xff09;<br \/>\n\u2514\u2534\u2500\u2500\u2500\u2500\u2500 10   &#xff1a;\u670d\u52a1\u7f16\u53f7&#xff08;10 &#061; \u4ea4\u6613\u670d\u52a1&#xff09;<br \/>\n       06   &#xff1a;\u9879\u76ee\u7ec4\u7f16\u53f7&#xff08;06 &#061; \u7535\u5546\u9879\u76ee\u7ec4&#xff09;<\/p>\n<p>\u62c6\u5f00\u770b&#xff1a;06 \u9879\u76ee\u7ec4 \u2192 10 \u4ea4\u6613\u670d\u52a1 \u2192 03 \u652f\u4ed8\u6a21\u5757 \u2192 25 \u7b2c 25 \u4e2a\u9519\u8bef\u3002<\/p>\n<p>\u4e3a\u4ec0\u4e48\u6bcf\u6bb5\u53ea\u6709\u4e24\u4f4d&#xff08;\u4e0a\u9650 99&#xff09;&#xff1f; \u56e0\u4e3a\u4e24\u4f4d\u662f\u4f60\u88ab\u8feb\u505a&#034;\u5408\u5e76\u540c\u7c7b\u9879&#034;\u7684\u7ea6\u675f\u3002\u4e00\u4e2a\u6a21\u5757\u7684\u9519\u8bef\u7801\u8d85\u8fc7 99 \u4e2a&#xff0c;\u8bf4\u660e\u4e0d\u662f\u9519\u8bef\u7801\u4e0d\u591f\u7528&#xff0c;\u662f\u8fd9\u4e2a\u6a21\u5757\u7684\u804c\u8d23\u592a\u6742&#xff0c;\u8be5\u62c6\u4e86\u3002\u8fd9\u4e2a\u4e0a\u9650\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u67b6\u6784\u62a5\u8b66\u5668\u3002<\/p>\n<p>\u6bcf\u4e00\u6bb5\u600e\u4e48\u5206\u914d&#xff0c;\u8fdb\u9879\u76ee\u7b2c\u4e00\u5929\u5c31\u8981\u5b9a\u6b7b\u3002 \u6211\u4eec\u7684\u7ea6\u5b9a\u662f&#xff1a;<\/p>\n<table>\n<tr>\u6bb5\u4f4d\u4f4d\u6570\u8c01\u5206\u914d\u53d8\u66f4\u9891\u7387<\/tr>\n<tbody>\n<tr>\n<td>\u9879\u76ee\u7ec4<\/td>\n<td>2<\/td>\n<td>\u67b6\u6784\u7ec4\u7edf\u4e00\u5206<\/td>\n<td>\u51e0\u4e4e\u4e0d\u53d8<\/td>\n<\/tr>\n<tr>\n<td>\u670d\u52a1<\/td>\n<td>2<\/td>\n<td>\u67b6\u6784\u7ec4\u7edf\u4e00\u5206<\/td>\n<td>\u65b0\u670d\u52a1\u4e0a\u7ebf\u65f6<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u5757<\/td>\n<td>2<\/td>\n<td>\u670d\u52a1\u8d1f\u8d23\u4eba\u5206<\/td>\n<td>\u52a0\u65b0\u6a21\u5757\u65f6<\/td>\n<\/tr>\n<tr>\n<td>\u9519\u8bef\u7801<\/td>\n<td>2<\/td>\n<td>\u6a21\u5757\u8d1f\u8d23\u4eba\u5206<\/td>\n<td>\u968f\u65f6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>Go \u91cc\u7684\u843d\u5730\u5199\u6cd5<\/h4>\n<p>\u9519\u8bef\u7801\u4e0d\u80fd\u53ea\u662f\u4e00\u4e2a int \u5e38\u91cf&#xff0c;\u5b83\u5f97\u5e26\u4e0a\u4e09\u6837\u4e1c\u897f&#xff1a;\u7ed9\u4eba\u770b\u7684\u6d88\u606f\u3001\u7ed9\u5ba2\u6237\u7aef\u7684\u63d0\u793a\u3001\u5bf9\u5e94\u7684 HTTP \u72b6\u6001\u7801\u3002<\/p>\n<p><span class=\"token comment\">\/\/ internal\/pkg\/errcode\/errcode.go<\/span><br \/>\n<span class=\"token keyword\">package<\/span> errcode<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token string\">&#034;net\/http&#034;<\/span><\/p>\n<p><span class=\"token keyword\">type<\/span> Code <span class=\"token keyword\">struct<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    Code    <span class=\"token builtin\">int<\/span>    <span class=\"token comment\">\/\/ 8 \u4f4d\u4e1a\u52a1\u7801<\/span><br \/>\n    Msg     <span class=\"token builtin\">string<\/span> <span class=\"token comment\">\/\/ \u5185\u90e8\u65e5\u5fd7\u7528&#xff1a;\u8bf4\u6e05\u662f\u4ec0\u4e48\u9519\u4e86<\/span><br \/>\n    UserMsg <span class=\"token builtin\">string<\/span> <span class=\"token comment\">\/\/ \u8fd4\u56de\u7ed9\u7528\u6237&#xff1a;\u544a\u8bc9\u4ed6\u600e\u4e48\u529e<\/span><br \/>\n    Status  <span class=\"token builtin\">int<\/span>    <span class=\"token comment\">\/\/ \u5bf9\u5e94\u7684 HTTP \u72b6\u6001\u7801<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">var<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token comment\">\/\/ 06 10 03 \u6bb5&#xff1a;\u4ea4\u6613\u670d\u52a1-\u652f\u4ed8\u6a21\u5757<\/span><br \/>\n    PayOrderNotFound <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>Code<span class=\"token punctuation\">{<\/span><span class=\"token number\">06100301<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;payment order not found&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u8ba2\u5355\u4e0d\u5b58\u5728&#xff0c;\u8bf7\u8fd4\u56de\u8ba2\u5355\u5217\u8868\u5237\u65b0\u540e\u91cd\u8bd5&#034;<\/span><span class=\"token punctuation\">,<\/span> http<span class=\"token punctuation\">.<\/span>StatusNotFound<span class=\"token punctuation\">}<\/span><br \/>\n    PayAmountInvalid <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>Code<span class=\"token punctuation\">{<\/span><span class=\"token number\">06100302<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;payment amount &lt;&#061; 0&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u652f\u4ed8\u91d1\u989d\u6709\u8bef&#xff0c;\u8bf7\u8fd4\u56de\u8ba2\u5355\u9875\u786e\u8ba4\u91d1\u989d&#034;<\/span><span class=\"token punctuation\">,<\/span> http<span class=\"token punctuation\">.<\/span>StatusBadRequest<span class=\"token punctuation\">}<\/span><br \/>\n    PayDuplicateCall <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>Code<span class=\"token punctuation\">{<\/span><span class=\"token number\">06100325<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;duplicate notify ignored&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u8fd9\u7b14\u652f\u4ed8\u5df2\u5904\u7406\u5b8c\u6210&#xff0c;\u65e0\u9700\u91cd\u590d\u64cd\u4f5c&#034;<\/span><span class=\"token punctuation\">,<\/span> http<span class=\"token punctuation\">.<\/span>StatusOK<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">func<\/span> <span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">*<\/span>Code<span class=\"token punctuation\">)<\/span> <span class=\"token function\">Error<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token builtin\">string<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">return<\/span> c<span class=\"token punctuation\">.<\/span>Msg <span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5173\u952e\u5728\u4e8e Msg \u548c UserMsg \u5206\u5f00&#xff1a;<\/p>\n<ul>\n<li>Msg \u8fdb\u65e5\u5fd7&#xff0c;\u5199\u6e05\u695a&#034;\u9519\u5728\u54ea&#034;&#xff0c;\u65b9\u4fbf\u4f60\u641c<\/li>\n<li>UserMsg \u8fd4\u56de\u524d\u7aef&#xff0c;\u5199\u6e05\u695a&#034;\u600e\u4e48\u529e&#034;&#xff0c;\u7edd\u4e0d\u80fd\u51fa\u73b0\u6280\u672f\u7ec6\u8282<\/li>\n<\/ul>\n<p>\u8fd9\u6b63\u662f&#034;\u5bf9\u7528\u6237\u63a5\u53e3\u5e94\u8be5\u544a\u8bc9\u7528\u6237\u600e\u4e48\u505a&#xff0c;\u800c\u4e0d\u662f\u9519\u5728\u54ea\u91cc&#034;\u7684\u610f\u601d\u3002\u7528\u6237\u770b\u5230&#034;DB connection refused&#034;\u53ea\u4f1a\u6765\u9a82\u4f60&#xff0c;\u770b\u5230&#034;\u7cfb\u7edf\u7e41\u5fd9&#xff0c;\u8bf7 30 \u79d2\u540e\u91cd\u8bd5&#034;\u624d\u77e5\u9053\u8be5\u5e72\u561b\u3002<\/p>\n<h3>\u516d\u3001HTTP \u72b6\u6001\u7801\u4e0e\u54cd\u5e94\u4f53&#xff1a;\u4e09\u5c42\u5404\u7ba1\u4ec0\u4e48<\/h3>\n<h4>\u72b6\u6001\u7801\u7684\u5206\u5de5<\/h4>\n<table>\n<tr>\u72b6\u6001\u7801\u542b\u4e49\u8c01\u629b\u51fa\u7684<\/tr>\n<tbody>\n<tr>\n<td>200<\/td>\n<td>\u8bf7\u6c42\u6210\u529f\u6267\u884c<\/td>\n<td>\u4e1a\u52a1\u4ee3\u7801<\/td>\n<\/tr>\n<tr>\n<td>401<\/td>\n<td>\u672a\u8ba4\u8bc1&#xff08;\u6ca1\u767b\u5f55\u3001token \u8fc7\u671f&#xff09;<\/td>\n<td>\u8ba4\u8bc1\u4e2d\u95f4\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>403<\/td>\n<td>\u5df2\u8ba4\u8bc1\u4f46\u65e0\u6743\u9650<\/td>\n<td>\u9274\u6743\u4e2d\u95f4\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>404<\/td>\n<td>\u8d44\u6e90\u4e0d\u5b58\u5728<\/td>\n<td>\u4e1a\u52a1\u4ee3\u7801 \/ \u8def\u7531<\/td>\n<\/tr>\n<tr>\n<td>500<\/td>\n<td>\u670d\u52a1\u7aef\u81ea\u8eab\u51fa\u4e86\u95ee\u9898<\/td>\n<td>panic \u6062\u590d\u4e2d\u95f4\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>503<\/td>\n<td>\u670d\u52a1\u6682\u65f6\u4e0d\u53ef\u7528<\/td>\n<td>\u7f51\u5173\u3001\u9650\u6d41\u5668\u3001\u5bb9\u5668\u7f16\u6392\u5c42<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e24\u4e2a\u6700\u5bb9\u6613\u641e\u6df7\u7684&#xff1a;<\/p>\n<p>401 vs 403\u3002 401 \u662f&#034;\u6211\u4e0d\u77e5\u9053\u4f60\u662f\u8c01&#034;&#xff0c;403 \u662f&#034;\u6211\u77e5\u9053\u4f60\u662f\u8c01&#xff0c;\u4f46\u4f60\u4e0d\u80fd\u5e72\u8fd9\u4e2a&#034;\u3002\u524d\u7aef\u5904\u7406\u5b8c\u5168\u4e0d\u540c&#xff1a;401 \u8df3\u767b\u5f55\u9875&#xff0c;403 \u5f39\u65e0\u6743\u9650\u63d0\u793a\u3002<\/p>\n<p>500 vs 503\u3002 500 \u662f\u4f60\u7684\u4ee3\u7801\u5199\u9519\u4e86&#xff0c;503 \u662f&#034;\u6211\u73b0\u5728\u4e0d\u80fd\u670d\u52a1&#034;&#xff08;\u9650\u6d41\u3001\u7194\u65ad\u3001\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\u3001\u6b63\u5728\u53d1\u5e03&#xff09;\u3002503 \u901a\u5e38\u662f\u522b\u4eba\u629b\u7684&#xff0c;\u4e0d\u662f\u4f60\u7684\u4e1a\u52a1\u4ee3\u7801\u3002<\/p>\n<h4>\u7edf\u4e00\u54cd\u5e94\u7ed3\u6784<\/h4>\n<p><span class=\"token punctuation\">{<\/span><span class=\"token string-property property\">&#034;success&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-property property\">&#034;code&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-property property\">&#034;msg&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string-property property\">&#034;data&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>\u56db\u6761\u7ea6\u5b9a&#xff1a;<\/p>\n<li>code \u6210\u529f\u65f6\u662f 0&#xff0c;\u5931\u8d25\u65f6\u662f 8 \u4f4d\u4e1a\u52a1\u7801\u3002 \u4e0d\u8981\u6210\u529f\u4e5f\u8fd4\u56de 06100000&#xff0c;\u524d\u7aef\u5224\u65ad\u6210\u672c\u9ad8\u3002<\/li>\n<li>\u5217\u8868\u4e0d\u8981\u5957\u592a\u591a\u5c42\u3002 {&#034;data&#034;:{&#034;list&#034;:{&#034;items&#034;:[&#8230;]}}} \u8fd9\u79cd\u4e09\u5c42\u5d4c\u5957&#xff0c;\u524d\u7aef\u6bcf\u6b21\u53d6\u503c\u90fd\u8981\u5199 res.data.data.list.items\u3002\u76f4\u63a5 {&#034;data&#034;:[&#8230;], &#034;total&#034;: 100}\u3002<\/li>\n<li>\u7edd\u4e0d\u66b4\u9732\u4e0d\u5b89\u5168\u7684\u9519\u8bef\u4fe1\u606f\u3002 \u6570\u636e\u5e93\u8fde\u63a5\u4e32\u3001\u5185\u7f51 IP\u3001SQL \u8bed\u53e5\u3001\u5806\u6808&#xff0c;\u4e00\u4e2a\u90fd\u4e0d\u80fd\u51fa\u73b0\u5728\u54cd\u5e94\u91cc\u3002\u8fd9\u4e9b\u53ea\u8fdb\u65e5\u5fd7\u3002<\/li>\n<li>msg \u8981\u80fd\u76f4\u63a5\u5c55\u793a\u7ed9\u7528\u6237\u3002 \u524d\u7aef\u4e0d\u8be5\u518d\u505a\u9519\u8bef\u7801\u5b57\u5178\u6620\u5c04\u2014\u2014\u90a3\u4e2a\u5b57\u5178\u8fdf\u65e9\u548c\u540e\u7aef\u4e0d\u540c\u6b65\u3002<\/li>\n<p>Go \u91cc\u6211\u662f\u8fd9\u4e48\u5c01\u7684&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ internal\/pkg\/response\/response.go<\/span><br \/>\n<span class=\"token keyword\">package<\/span> response<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token string\">&#034;net\/http&#034;<\/span><\/p>\n<p>    <span class=\"token string\">&#034;github.com\/gin-gonic\/gin&#034;<\/span><br \/>\n    <span class=\"token string\">&#034;myapp\/internal\/pkg\/errcode&#034;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">type<\/span> Body <span class=\"token keyword\">struct<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    Success <span class=\"token builtin\">bool<\/span>        <span class=\"token string\">&#096;json:&#034;success&#034;&#096;<\/span><br \/>\n    Code    <span class=\"token builtin\">int<\/span>         <span class=\"token string\">&#096;json:&#034;code&#034;&#096;<\/span><br \/>\n    Msg     <span class=\"token builtin\">string<\/span>      <span class=\"token string\">&#096;json:&#034;msg&#034;&#096;<\/span><br \/>\n    Data    <span class=\"token keyword\">interface<\/span><span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span> <span class=\"token string\">&#096;json:&#034;data&#034;&#096;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">func<\/span> <span class=\"token function\">OK<\/span><span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">*<\/span>gin<span class=\"token punctuation\">.<\/span>Context<span class=\"token punctuation\">,<\/span> data <span class=\"token keyword\">interface<\/span><span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    c<span class=\"token punctuation\">.<\/span><span class=\"token function\">JSON<\/span><span class=\"token punctuation\">(<\/span>http<span class=\"token punctuation\">.<\/span>StatusOK<span class=\"token punctuation\">,<\/span> Body<span class=\"token punctuation\">{<\/span>Success<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> Code<span class=\"token punctuation\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> Data<span class=\"token punctuation\">:<\/span> data<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">func<\/span> <span class=\"token function\">Fail<\/span><span class=\"token punctuation\">(<\/span>c <span class=\"token operator\">*<\/span>gin<span class=\"token punctuation\">.<\/span>Context<span class=\"token punctuation\">,<\/span> e <span class=\"token operator\">*<\/span>errcode<span class=\"token punctuation\">.<\/span>Code<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5185\u90e8\u7ec6\u8282\u53ea\u8fdb\u65e5\u5fd7&#xff0c;\u54cd\u5e94\u91cc\u53ea\u7ed9 UserMsg<\/span><br \/>\n    c<span class=\"token punctuation\">.<\/span><span class=\"token function\">Error<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><br \/>\n    c<span class=\"token punctuation\">.<\/span><span class=\"token function\">JSON<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">.<\/span>Status<span class=\"token punctuation\">,<\/span> Body<span class=\"token punctuation\">{<\/span>Success<span class=\"token punctuation\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span> Code<span class=\"token punctuation\">:<\/span> e<span class=\"token punctuation\">.<\/span>Code<span class=\"token punctuation\">,<\/span> Msg<span class=\"token punctuation\">:<\/span> e<span class=\"token punctuation\">.<\/span>UserMsg<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6ce8\u610f Fail \u91cc\u90a3\u884c c.Error(e)&#xff1a;\u65e5\u5fd7\u91cc\u8bb0\u7684\u662f Msg&#xff08;\u542b\u6280\u672f\u7ec6\u8282&#xff09;&#xff0c;\u54cd\u5e94\u91cc\u7ed9\u7684\u662f UserMsg&#xff08;\u4eba\u80fd\u770b\u61c2\u7684\u8bdd&#xff09;\u3002\u8fd9\u6761\u5206\u79bb\u505a\u597d&#xff0c;\u7ebf\u4e0a\u6392\u969c\u4f1a\u8212\u670d\u5f88\u591a\u2014\u2014\u4f60\u641c\u65e5\u5fd7\u80fd\u641c\u5230\u7cbe\u786e\u539f\u56e0&#xff0c;\u7528\u6237\u4e5f\u4e0d\u4f1a\u770b\u5230\u4e0d\u8be5\u770b\u7684\u3002<\/p>\n<h3>\u4e03\u3001\u914d\u7f6e&#xff1a;\u56db\u7c7b\u7684\u8fb9\u754c\u5728\u54ea<\/h3>\n<p>\u914d\u7f6e\u662f\u6700\u5bb9\u6613\u4e71\u7684\u5730\u65b9\u3002\u6211\u4eec\u6309&#034;\u53d8\u66f4\u65b9\u5f0f&#034;\u5206\u56db\u7c7b&#xff1a;<\/p>\n<table>\n<tr>\u7c7b\u578b\u53d8\u66f4\u65b9\u5f0f\u5178\u578b\u5185\u5bb9\u5b58\u653e\u4f4d\u7f6e<\/tr>\n<tbody>\n<tr>\n<td>\u9759\u6001\u914d\u7f6e<\/td>\n<td>\u6539\u5b8c\u8981\u53d1\u7248<\/td>\n<td>DB \u5730\u5740\u3001Redis \u5730\u5740\u3001\u4e2d\u95f4\u4ef6\u8fde\u63a5\u4e32<\/td>\n<td>configs\/config.yaml<\/td>\n<\/tr>\n<tr>\n<td>\u52a8\u6001\u914d\u7f6e<\/td>\n<td>\u8fd0\u884c\u65f6\u70ed\u66f4\u65b0<\/td>\n<td>\u9650\u6d41\u9608\u503c\u3001\u5f00\u5173\u3001\u7070\u5ea6\u6bd4\u4f8b<\/td>\n<td>\u914d\u7f6e\u4e2d\u5fc3&#xff08;Etcd \/ Nacos \/ Apollo&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u73af\u5883\u53d8\u91cf<\/td>\n<td>\u5bb9\u5668\u542f\u52a8\u65f6\u6ce8\u5165<\/td>\n<td>\u73af\u5883\u6807\u8bc6\u3001Pod \u540d\u3001\u5bc6\u94a5<\/td>\n<td>\u5bb9\u5668 env<\/td>\n<\/tr>\n<tr>\n<td>\u5e38\u91cf<\/td>\n<td>\u4e0d\u6539<\/td>\n<td>\u4e1a\u52a1\u56fa\u5b9a\u503c&#xff08;\u6bd4\u5982&#034;\u6700\u591a 3 \u6b21\u91cd\u8bd5&#034;&#xff09;<\/td>\n<td>\u4ee3\u7801\u5e38\u91cf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5224\u65ad\u6807\u51c6\u5c31\u4e00\u53e5\u8bdd&#xff1a;\u8fd9\u4e1c\u897f\u591a\u4e45\u53d8\u4e00\u6b21\u3001\u53d8\u4e86\u8981\u4e0d\u8981\u53d1\u7248\u3002<\/p>\n<ul>\n<li>\u4e00\u5e74\u6539\u4e00\u6b21 \u2192 \u9759\u6001\u914d\u7f6e<\/li>\n<li>\u4e00\u5929\u6539\u51e0\u6b21 \u2192 \u52a8\u6001\u914d\u7f6e&#xff08;\u4f46\u8981\u5c0f\u5fc3&#xff0c;\u89c1\u540e\u9762\u7684\u5751&#xff09;<\/li>\n<li>\u6bcf\u4e2a\u73af\u5883\u4e0d\u540c \u2192 \u73af\u5883\u53d8\u91cf<\/li>\n<li>\u4ece\u6765\u4e0d\u6539 \u2192 \u5e38\u91cf&#xff0c;\u522b\u505a\u6210\u914d\u7f6e\u9879<\/li>\n<\/ul>\n<h4>\u914d\u7f6e\u8bbe\u8ba1 6 \u6761\u7eaa\u5f8b<\/h4>\n<li>\u4e2d\u95f4\u4ef6\u8fde\u63a5\u4fe1\u606f\u7528\u7edf\u4e00\u6a21\u677f\u3002 \u5341\u4e2a\u4eba\u5341\u79cd\u5199\u6cd5&#xff08;\u6709\u4eba\u5199 db_host&#xff0c;\u6709\u4eba\u5199 database.host&#xff09;&#xff0c;\u6700\u540e\u6ca1\u4eba\u77e5\u9053\u5168\u8c8c\u3002\u7ed9\u4e2a\u6a21\u677f &#043; \u5c01\u88c5\u5e93\u3002<\/li>\n<li>\u914d\u7f6e\u503c\u8981\u6821\u9a8c\u8303\u56f4\u3002 \u7aef\u53e3\u5199 99999\u3001\u8d85\u65f6\u5199 0\u3001\u8d85\u65f6\u5199 -1&#xff0c;\u8fd9\u4e9b\u5728\u542f\u52a8\u65f6\u5c31\u8be5 panic \u6389\u3002\u5b81\u53ef\u542f\u52a8\u5931\u8d25&#xff0c;\u4e0d\u8981\u5e26\u75c5\u8fd0\u884c\u3002<\/li>\n<li>\u547d\u540d\u8981\u8bed\u4e49\u5316 &#043; \u5e26\u5355\u4f4d\u3002 timeout: 30 \u662f\u79d2\u8fd8\u662f\u6beb\u79d2&#xff1f;\u5199\u6210 request_timeout_seconds: 30 \u6216 request_timeout: 30s\u3002<\/li>\n<li>\u914d\u7f6e\u53d8\u66f4\u4e5f\u8981 review\u3002 \u914d\u7f6e\u9519\u8bef\u5bfc\u81f4\u7684\u4e8b\u6545&#xff0c;\u6bd4\u4ee3\u7801 bug \u591a\u5f97\u591a&#xff0c;\u800c\u4e14\u66f4\u96be\u67e5\u3002<\/li>\n<li>\u4e0d\u7528\u7684\u914d\u7f6e\u53ca\u65f6\u5220\u3002 \u7559\u7740\u7684\u5e9f\u5f03\u914d\u7f6e\u9879&#xff0c;\u603b\u6709\u4e00\u5929\u4f1a\u88ab\u67d0\u4e2a\u65b0\u4eba\u5f53\u771f\u6539\u3002<\/li>\n<li>\u8bb0\u5f55\u53d8\u66f4\u5386\u53f2 &#043; \u53ef\u56de\u6eda\u3002 \u914d\u7f6e\u4e2d\u5fc3\u8981\u80fd\u70b9\u56de\u6eda&#xff0c;\u4e0d\u7136\u6539\u574f\u4e86\u53ea\u80fd\u624b\u5fd9\u811a\u4e71\u6539\u56de\u53bb\u3002<\/li>\n<h4>\u914d\u7f6e\u5b89\u5168\u7684 3 \u6761\u7ea2\u7ebf<\/h4>\n<li>\u654f\u611f\u914d\u7f6e\u4e0d\u51c6\u786c\u7f16\u7801\u3002 DB \u5bc6\u7801\u3001AK\/SK\u3001\u79c1\u94a5&#xff0c;\u4e00\u4e2a\u5b57\u90fd\u4e0d\u80fd\u5199\u8fdb .go \u6216\u63d0\u4ea4\u8fdb git\u3002<\/li>\n<li>\u654f\u611f\u914d\u7f6e\u7981\u6b62\u4efb\u4f55\u5f62\u5f0f\u7684\u8f93\u51fa\u3002 \u65e5\u5fd7\u3001panic \u4fe1\u606f\u3001\u63a5\u53e3\u54cd\u5e94\u3001\u5065\u5eb7\u68c0\u67e5\u7aef\u70b9&#xff0c;\u5168\u4e0d\u80fd\u5e26\u3002<\/li>\n<li>\u4e25\u683c\u63a7\u5236\u8bbf\u95ee\u6743\u9650\u3002 \u914d\u7f6e\u4e2d\u5fc3\u91cc\u8c01\u80fd\u770b\u8c01\u80fd\u6539&#xff0c;\u8981\u5206\u89d2\u8272\u3002<\/li>\n<h4>viper \u843d\u5730 &#043; \u4e09\u4e2a\u771f\u5b9e\u7684\u5751<\/h4>\n<p><span class=\"token comment\">\/\/ internal\/config\/config.go<\/span><br \/>\n<span class=\"token keyword\">package<\/span> config<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token string\">&#034;strings&#034;<\/span><br \/>\n    <span class=\"token string\">&#034;time&#034;<\/span><\/p>\n<p>    <span class=\"token string\">&#034;github.com\/spf13\/viper&#034;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">type<\/span> Config <span class=\"token keyword\">struct<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    Env      <span class=\"token builtin\">string<\/span>         <span class=\"token string\">&#096;mapstructure:&#034;env&#034;&#096;<\/span><br \/>\n    HTTP     HTTPConfig     <span class=\"token string\">&#096;mapstructure:&#034;http&#034;&#096;<\/span><br \/>\n    Database DatabaseConfig <span class=\"token string\">&#096;mapstructure:&#034;database&#034;&#096;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">type<\/span> HTTPConfig <span class=\"token keyword\">struct<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    Addr           <span class=\"token builtin\">string<\/span>        <span class=\"token string\">&#096;mapstructure:&#034;addr&#034;&#096;<\/span><br \/>\n    RequestTimeout time<span class=\"token punctuation\">.<\/span>Duration <span class=\"token string\">&#096;mapstructure:&#034;request_timeout&#034;&#096;<\/span> <span class=\"token comment\">\/\/ \u5199 30s \u800c\u4e0d\u662f 30<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">type<\/span> DatabaseConfig <span class=\"token keyword\">struct<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    DSN          <span class=\"token builtin\">string<\/span> <span class=\"token string\">&#096;mapstructure:&#034;dsn&#034;&#096;<\/span><br \/>\n    MaxOpenConns <span class=\"token builtin\">int<\/span>    <span class=\"token string\">&#096;mapstructure:&#034;max_open_conns&#034;&#096;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">func<\/span> <span class=\"token function\">Load<\/span><span class=\"token punctuation\">(<\/span>path <span class=\"token builtin\">string<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">*<\/span>Config<span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">error<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    v <span class=\"token operator\">:&#061;<\/span> viper<span class=\"token punctuation\">.<\/span><span class=\"token function\">New<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    v<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetConfigFile<\/span><span class=\"token punctuation\">(<\/span>path<span class=\"token punctuation\">)<\/span><br \/>\n    v<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetConfigType<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;yaml&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u73af\u5883\u53d8\u91cf\u8986\u76d6&#xff1a;APP_HTTP__ADDR \u4f1a\u8986\u76d6 http.addr<\/span><br \/>\n    v<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetEnvPrefix<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;APP&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    v<span class=\"token punctuation\">.<\/span><span class=\"token function\">SetEnvKeyReplacer<\/span><span class=\"token punctuation\">(<\/span>strings<span class=\"token punctuation\">.<\/span><span class=\"token function\">NewReplacer<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;.&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;__&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    v<span class=\"token punctuation\">.<\/span><span class=\"token function\">AutomaticEnv<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">if<\/span> err <span class=\"token operator\">:&#061;<\/span> v<span class=\"token punctuation\">.<\/span><span class=\"token function\">ReadInConfig<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> err <span class=\"token operator\">!&#061;<\/span> <span class=\"token boolean\">nil<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">nil<\/span><span class=\"token punctuation\">,<\/span> err<br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">var<\/span> c Config<br \/>\n    <span class=\"token keyword\">if<\/span> err <span class=\"token operator\">:&#061;<\/span> v<span class=\"token punctuation\">.<\/span><span class=\"token function\">Unmarshal<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>c<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> err <span class=\"token operator\">!&#061;<\/span> <span class=\"token boolean\">nil<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">nil<\/span><span class=\"token punctuation\">,<\/span> err<br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&amp;<\/span>c<span class=\"token punctuation\">,<\/span> c<span class=\"token punctuation\">.<\/span><span class=\"token function\">validate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token comment\">\/\/ \u8303\u56f4\u6821\u9a8c\u653e\u6700\u540e&#xff0c;\u914d\u7f6e\u4e0d\u5408\u6cd5\u76f4\u63a5\u62d2\u7edd\u542f\u52a8<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e09\u4e2a\u5751&#xff0c;\u90fd\u662f\u6211\u4eec\u8e29\u8fc7\u5e76\u5199\u8fdb runbook \u7684&#xff1a;<\/p>\n<p>\u5751 1&#xff1a;\u73af\u5883\u53d8\u91cf\u8986\u76d6\u987a\u5e8f\u3002 AutomaticEnv() \u53ea\u5bf9 Unmarshal \u8ba4\u8bc6\u4e0d\u5230\u7684\u952e\u751f\u6548&#xff0c;\u5d4c\u5957\u7ed3\u6784\u7ecf\u5e38\u8986\u76d6\u4e0d\u4e0a\u3002\u6211\u4eec\u7684\u89e3\u6cd5\u662f\u2014\u2014\u5bc6\u94a5\u8fd9\u7c7b\u5fc5\u987b\u7528\u73af\u5883\u53d8\u91cf\u7684\u4e1c\u897f&#xff0c;\u4e0d\u8d70 viper&#xff0c;\u76f4\u63a5 os.Getenv\u3002\u522b\u5728\u4e00\u4e2a\u5e93\u91cc\u540c\u65f6\u6307\u671b\u4e24\u5957\u8bed\u4e49\u3002<\/p>\n<p>\u5751 2&#xff1a;WatchConfig() \u662f\u4e2a\u5e38\u9a7b goroutine\u3002 \u70ed\u66f4\u65b0\u770b\u8d77\u6765\u5f88\u7f8e&#xff0c;\u4f46\u4f60\u5982\u679c\u53ea\u5728 main \u91cc\u8c03\u4e00\u6b21\u5c31\u6ca1\u7ba1\u5b83&#xff0c;\u8fd9\u4e2a goroutine \u6c38\u8fdc\u4e0d\u4f1a\u9000\u51fa&#xff0c;\u6d4b\u8bd5\u65f6\u8fd8\u4f1a\u83ab\u540d\u8bfb\u5230\u4e0a\u4e00\u4e2a\u6d4b\u8bd5\u7684\u914d\u7f6e\u3002\u8981\u7528\u5c31\u5f97\u914d OnConfigChange&#xff0c;\u5e76\u4e14\u60f3\u6e05\u695a&#034;\u914d\u7f6e\u53d8\u4e86\u4e4b\u540e&#xff0c;\u5df2\u7ecf\u5efa\u7acb\u7684\u8fde\u63a5\u6c60\u600e\u4e48\u529e&#034;\u2014\u2014\u5f88\u591a\u914d\u7f6e\u662f\u4e0d\u80fd\u70ed\u7684\u3002<\/p>\n<p>\u5751 3&#xff1a;viper.Debug() \u4f1a\u628a\u6240\u6709\u914d\u7f6e\u6253\u5230 stdout\u3002 \u6709\u4eba\u4e3a\u4e86\u6392\u67e5\u4e34\u65f6\u52a0\u4e86\u4e00\u884c&#xff0c;\u5fd8\u4e86\u5220&#xff0c;\u5bc6\u7801\u5c31\u8fdb\u65e5\u5fd7\u4e86\u3002\u8fd9\u5c31\u662f\u7ea2\u7ebf 2 \u7684\u7531\u6765\u3002<\/p>\n<p>\u6211\u7684\u5efa\u8bae\u5f88\u4fdd\u5b88&#xff1a;\u5927\u90e8\u5206\u670d\u52a1\u4e0d\u9700\u8981\u52a8\u6001\u914d\u7f6e\u3002 \u5148\u628a\u9759\u6001\u914d\u7f6e &#043; \u73af\u5883\u53d8\u91cf\u505a\u5e72\u51c0&#xff0c;\u771f\u6709&#034;\u4e00\u5929\u6539\u51e0\u6b21&#034;\u7684\u9700\u6c42\u518d\u4e0a\u914d\u7f6e\u4e2d\u5fc3\u3002<\/p>\n<h3>\u516b\u30018 \u4e2a\u9762\u8bd5\u8ffd\u95ee<\/h3>\n<p>\u8fd9\u51e0\u4e2a\u95ee\u9898\u5728\u6211\u4eec\u7684\u9762\u8bd5\u91cc\u51fa\u73b0\u9891\u7387\u6700\u9ad8&#xff0c;\u7b54\u6848\u6211\u76f4\u63a5\u7ed9\u3002<\/p>\n<p>Q1&#xff1a;internal \u76ee\u5f55\u662f\u7ea6\u5b9a\u8fd8\u662f\u5f3a\u5236&#xff1f; \u5f3a\u5236\u3002Go \u7f16\u8bd1\u5668\u4f1a\u7ed9 use of internal package &#8230; not allowed\u3002\u5b83\u9650\u5236\u7684\u662f&#034;\u5bfc\u5165\u8def\u5f84\u542b internal \u7684\u5305&#xff0c;\u53ea\u80fd\u88ab internal \u7236\u76ee\u5f55\u6811\u5185\u7684\u4ee3\u7801\u5bfc\u5165&#034;\u3002<\/p>\n<p>Q2&#xff1a;cmd \u4e0b\u4e3a\u4ec0\u4e48\u8981\u5206\u591a\u4e2a\u5b50\u76ee\u5f55&#xff1f; \u4e00\u4e2a\u5b50\u76ee\u5f55 &#061; \u4e00\u4e2a\u72ec\u7acb\u4e8c\u8fdb\u5236\u3002api-server \u548c worker \u72ec\u7acb\u7f16\u8bd1\u3001\u72ec\u7acb\u6269\u7f29\u5bb9&#xff0c;\u5171\u7528 internal\/&#xff0c;\u907f\u514d\u628a\u6574\u4e2a\u670d\u52a1\u590d\u5236\u6210\u4e24\u4efd\u3002<\/p>\n<p>Q3&#xff1a;DELETE \u4e3a\u4ec0\u4e48\u662f\u5e42\u7b49\u7684&#xff0c;\u5b83\u660e\u660e\u6539\u4e86\u72b6\u6001&#xff1f; \u5e42\u7b49\u770b\u7684\u662f&#034;\u591a\u6b21\u6267\u884c\u540e\u6700\u7ec8\u72b6\u6001\u4e00\u81f4&#034;&#xff0c;\u4e0d\u662f&#034;\u72b6\u6001\u6ca1\u53d8&#034;\u3002\u5220\u4e24\u6b21&#xff0c;\u8d44\u6e90\u90fd\u662f&#034;\u4e0d\u5b58\u5728&#034;&#xff0c;\u6700\u7ec8\u4e00\u81f4\u3002<\/p>\n<p>Q4&#xff1a;POST \u600e\u4e48\u505a\u5230\u5e42\u7b49&#xff1f; \u4e1a\u52a1\u4fa7\u5f15\u5165\u5e42\u7b49\u952e&#xff08;\u6e20\u9053\u6d41\u6c34\u53f7 \/ \u5ba2\u6237\u7aef\u751f\u6210\u7684 request id&#xff09;&#xff0c;\u843d\u5e93\u524d\u7528 Redis SETNX \u6216\u6570\u636e\u5e93\u552f\u4e00\u7d22\u5f15\u505a\u53bb\u91cd&#xff0c;\u91cd\u590d\u8bf7\u6c42\u76f4\u63a5\u8fd4\u56de\u6210\u529f\u3002TTL \u8981\u8986\u76d6\u5bf9\u65b9\u7684\u91cd\u8bd5\u7a97\u53e3\u3002<\/p>\n<p>Q5&#xff1a;\u4e3a\u4ec0\u4e48\u4e0d\u7528\u5168\u5c40\u7edf\u4e00\u9519\u8bef\u7801&#xff1f; \u649e\u53f7\u3001\u65e0\u6cd5\u5b9a\u4f4d\u6765\u6e90\u3001\u53ea\u589e\u4e0d\u51cf\u3002\u6309\u9879\u76ee\/\u670d\u52a1\/\u6a21\u5757\/\u9519\u8bef\u7801\u5206\u6bb5&#xff0c;\u7801\u672c\u8eab\u81ea\u5e26\u5f52\u5c5e\u4fe1\u606f\u3002<\/p>\n<p>Q6&#xff1a;\u4e1a\u52a1\u7801\u548c HTTP \u72b6\u6001\u7801\u662f\u4ec0\u4e48\u5173\u7cfb&#xff1f; HTTP \u72b6\u6001\u7801\u8868\u8fbe&#034;\u8fd9\u4e00\u5c42\u53d1\u751f\u4e86\u4ec0\u4e48&#034;&#xff08;\u6210\u529f\/\u672a\u8ba4\u8bc1\/\u65e0\u6743\u9650\/\u4e0d\u5b58\u5728\/\u670d\u52a1\u7aef\u9519\/\u4e0d\u53ef\u7528&#xff09;&#xff0c;\u4e1a\u52a1\u7801\u8868\u8fbe&#034;\u5177\u4f53\u54ea\u4e2a\u4e1a\u52a1\u7684\u54ea\u4e2a\u9519\u8bef&#034;\u3002\u4e24\u8005\u4e00\u8d77\u7528&#xff0c;\u522b\u53ea\u7528\u4e00\u4e2a\u3002<\/p>\n<p>Q7&#xff1a;\u914d\u7f6e\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5168\u90e8\u52a8\u6001\u5316&#xff1f; \u56e0\u4e3a\u5f88\u591a\u914d\u7f6e\u4f9d\u8d56&#034;\u8fdb\u7a0b\u542f\u52a8\u65f6\u7684\u72b6\u6001&#034;\u2014\u2014\u8fde\u63a5\u6c60\u5927\u5c0f\u3001\u76d1\u542c\u7aef\u53e3\u3001\u5e8f\u5217\u5316\u65b9\u5f0f\u3002\u70ed\u66f4\u65b0\u8fd9\u4e9b\u53ea\u4f1a\u5e26\u6765\u4e0d\u4e00\u81f4\u3002\u52a8\u6001\u914d\u7f6e\u53ea\u5e94\u8be5\u7ed9&#034;\u8bfb\u4e00\u6b21\u5c31\u80fd\u751f\u6548&#034;\u7684\u5f00\u5173\u7c7b\u53c2\u6570\u3002<\/p>\n<p>Q8&#xff1a;\u654f\u611f\u914d\u7f6e\u600e\u4e48\u7ba1&#xff1f; \u4e0d\u8fdb\u4ee3\u7801\u4ed3\u5e93&#xff0c;\u8d70\u73af\u5883\u53d8\u91cf\u6216\u5bc6\u94a5\u7ba1\u7406\u670d\u52a1&#xff1b;\u65e5\u5fd7\u548c\u54cd\u5e94\u91cc\u5168\u7a0b\u8131\u654f&#xff1b;\u914d\u7f6e\u4e2d\u5fc3\u6309\u89d2\u8272\u63a7\u6743\u9650\u3002<\/p>\n<p>&#x1f4a1; \u672c\u7ae0\u9762\u8bd5\u8981\u70b9<\/p>\n<ul>\n<li>\u76ee\u5f55\u7ed3\u6784\u6ca1\u6709\u5b98\u65b9\u6807\u51c6&#xff0c;\u80fd\u8bf4\u6e05&#034;\u54ea\u4e9b\u76ee\u5f55\u505a\u4e86\u4ec0\u4e48\u53d6\u820d&#034;\u6bd4\u80cc 25 \u4e2a\u76ee\u5f55\u66f4\u503c\u94b1<\/li>\n<li>internal \u662f\u7f16\u8bd1\u5668\u5f3a\u5236&#xff0c;\u8fd9\u662f\u80fd\u62c9\u5f00\u5dee\u8ddd\u7684\u7ec6\u8282<\/li>\n<li>\u5e42\u7b49\u7684\u5224\u636e\u662f&#034;\u6700\u7ec8\u72b6\u6001\u4e00\u81f4&#034;&#xff0c;POST \u5e42\u7b49\u9760\u5e42\u7b49\u952e &#043; SETNX\/\u552f\u4e00\u7d22\u5f15<\/li>\n<li>\u9519\u8bef\u7801\u5206\u6bb5\u7684\u771f\u6b63\u4ef7\u503c\u662f\u81ea\u5e26\u5f52\u5c5e\u4fe1\u606f &#043; 99 \u4e0a\u9650\u903c\u4f60\u62c6\u6a21\u5757<\/li>\n<li>Msg \u8fdb\u65e5\u5fd7\u3001UserMsg \u8fd4\u524d\u7aef&#xff0c;\u8fd9\u6761\u5206\u79bb\u662f\u5de5\u7a0b\u7d20\u517b\u7684\u5206\u6c34\u5cad<\/li>\n<\/ul>\n<hr \/>\n<p>\u8fd9\u5957\u9aa8\u67b6\u6211\u73b0\u5728\u6bcf\u4e2a\u65b0\u9879\u76ee\u90fd\u7167\u6284\u4e00\u904d&#xff0c;\u6539\u7684\u53ea\u6709 cmd\/ \u4e0b\u7684\u5165\u53e3\u540d\u548c internal\/ \u91cc\u7684\u6a21\u5757\u5212\u5206\u3002\u4e0b\u4e00\u7bc7\u6211\u4f1a\u5728\u8fd9\u5957\u9aa8\u67b6\u4e0a\u843d\u7b2c\u4e00\u4e2a\u771f\u5b9e\u9879\u76ee&#xff1a;\u7528 Gin &#043; GORM \u505a\u4e00\u5957\u5e26\u5206\u5c42\u3001\u5e26\u4e8b\u52a1\u3001\u5e26\u5e42\u7b49\u7684\u8ba2\u5355\u670d\u52a1&#xff0c;\u4ece\u5efa\u8868\u5230\u63a5\u53e3\u5230\u538b\u6d4b\u8d70\u4e00\u904d&#xff0c;\u6700\u540e\u628a\u4eca\u5929\u8fd9\u5f20\u9519\u8bef\u7801\u8868\u586b\u6ee1\u3002<\/p>\n<p>\u5982\u679c\u8fd9\u7bc7\u5bf9\u4f60\u6709\u7528&#xff0c;\u6536\u85cf\u4e00\u4e0b\u2014\u2014\u72af\u9519\u7684\u65f6\u5019\u4f60\u5c31\u662f\u9760\u8fd9\u5f20\u8868\u5b9a\u4f4d\u7684\u3002\u4e5f\u987a\u624b\u8ba2\u9605\u300c\u9879\u76ee\u5b9e\u6218\u300d\u4e13\u680f&#xff0c;\u540e\u9762\u6bcf\u7bc7\u90fd\u662f\u5728\u8fd9\u5957\u9aa8\u67b6\u4e0a\u53e0\u529f\u80fd&#xff0c;\u8df3\u7740\u770b\u4f1a\u65ad\u3002<\/p>\n<p>\u6700\u540e\u4e00\u4e2a\u95ee\u9898&#xff0c;\u4e00\u53e5\u8bdd\u5c31\u80fd\u7b54&#xff1a;\u4f60\u4eec\u9879\u76ee\u73b0\u5728\u6709\u51e0\u4e2a\u9876\u5c42\u76ee\u5f55&#xff1f;\u91cc\u9762\u6709\u51e0\u4e2a\u662f\u4e09\u4e2a\u6708\u6ca1\u4eba\u78b0\u8fc7\u7684&#xff1f; \u8bc4\u8bba\u533a\u804a\u804a&#xff0c;\u6211\u770b\u770b\u6709\u6ca1\u6709\u6bd4\u6211\u66f4\u72e0\u7684\u3002<\/p>\n<p>\u4f5c\u8005&#xff1a;\u5229\u5a01\u5c14xu | CSDN \u4e13\u680f\u300a\u9879\u76ee\u5b9e\u6218\u300b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u597d&#xff0c;\u6211\u662f\u5229\u5a01\u5c14xu\u3002<br \/>\n\u8fd9\u662f\u300c\u9879\u76ee\u5b9e\u6218\u300d\u4e13\u680f\u7684\u7b2c\u4e00\u7bc7\u3002\u524d\u9762\u5728\u9762\u8bd5\u516b\u80a1\u548c\u4fdd\u59c6\u7ea7\u7cfb\u5217\u91cc\u804a\u4e86\u592a\u591a\u539f\u7406&#xff0c;\u8fd9\u6b21\u6362\u4e2a\u89d2\u5ea6&#xff1a;\u4ece 0 \u628a\u4e00\u4e2a Go \u670d\u52a1\u642d\u8d77\u6765&#xff0c;\u5230\u5e95\u8be5\u5efa\u54ea\u4e9b\u76ee\u5f55\u3001\u63a5\u53e3\u600e\u4e48\u5b9a\u3001\u9519\u8bef\u7801\u600e\u4e48\u7f16\u3001\u914d\u7f6e\u600e\u4e48\u653e\u3002\u8fd9\u4e00\u7bc7\u662f\u6574\u4e2a\u4e13\u680f\u7684\u5730\u57fa&#xff0c;\u540e\u9762\u6240\u6709\u5b9e\u6218\u9879\u76ee\u90fd\u6309\u8fd9\u5957\u9aa8\u67b6\u6765\u3002<br \/>\n\u70b9\u540d\u4e00\u4e0b\u53d7\u4f17&#xff1a;\u80fd\u5199 Go\u3001\u80fd\u8dd1\u901a Gin \u7684 CRUD&#xff0c;\u4f46\u6ca1\u4ece\u96f6\u642d\u8fc7\u4e00\u4e2a\u80fd\u88ab\u4e09\u4e2a\u4eba\u4ee5\u4e0a\u534f\u4f5c\u7684\u5de5\u7a0b\u9aa8\u67b6\u7684\u540c\u5b66\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5728<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[746,3440,292,190,1348],"topic":[],"class_list":["post-117442","post","type-post","status-publish","format-standard","hentry","category-server","tag-golang","tag-restful","tag-292","tag-190","tag-1348"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117442.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4f60\u597d&#xff0c;\u6211\u662f\u5229\u5a01\u5c14xu\u3002 \u8fd9\u662f\u300c\u9879\u76ee\u5b9e\u6218\u300d\u4e13\u680f\u7684\u7b2c\u4e00\u7bc7\u3002\u524d\u9762\u5728\u9762\u8bd5\u516b\u80a1\u548c\u4fdd\u59c6\u7ea7\u7cfb\u5217\u91cc\u804a\u4e86\u592a\u591a\u539f\u7406&#xff0c;\u8fd9\u6b21\u6362\u4e2a\u89d2\u5ea6&#xff1a;\u4ece 0 \u628a\u4e00\u4e2a Go \u670d\u52a1\u642d\u8d77\u6765&#xff0c;\u5230\u5e95\u8be5\u5efa\u54ea\u4e9b\u76ee\u5f55\u3001\u63a5\u53e3\u600e\u4e48\u5b9a\u3001\u9519\u8bef\u7801\u600e\u4e48\u7f16\u3001\u914d\u7f6e\u600e\u4e48\u653e\u3002\u8fd9\u4e00\u7bc7\u662f\u6574\u4e2a\u4e13\u680f\u7684\u5730\u57fa&#xff0c;\u540e\u9762\u6240\u6709\u5b9e\u6218\u9879\u76ee\u90fd\u6309\u8fd9\u5957\u9aa8\u67b6\u6765\u3002 \u70b9\u540d\u4e00\u4e0b\u53d7\u4f17&#xff1a;\u80fd\u5199 Go\u3001\u80fd\u8dd1\u901a Gin \u7684 CRUD&#xff0c;\u4f46\u6ca1\u4ece\u96f6\u642d\u8fc7\u4e00\u4e2a\u80fd\u88ab\u4e09\u4e2a\u4eba\u4ee5\u4e0a\u534f\u4f5c\u7684\u5de5\u7a0b\u9aa8\u67b6\u7684\u540c\u5b66\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5728\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117442.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-24T13:48:22+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117442.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117442.html\",\"name\":\"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-24T13:48:22+00:00\",\"dateModified\":\"2026-10-24T13:48:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117442.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117442.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117442.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117442.html","og_locale":"zh_CN","og_type":"article","og_title":"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4f60\u597d&#xff0c;\u6211\u662f\u5229\u5a01\u5c14xu\u3002 \u8fd9\u662f\u300c\u9879\u76ee\u5b9e\u6218\u300d\u4e13\u680f\u7684\u7b2c\u4e00\u7bc7\u3002\u524d\u9762\u5728\u9762\u8bd5\u516b\u80a1\u548c\u4fdd\u59c6\u7ea7\u7cfb\u5217\u91cc\u804a\u4e86\u592a\u591a\u539f\u7406&#xff0c;\u8fd9\u6b21\u6362\u4e2a\u89d2\u5ea6&#xff1a;\u4ece 0 \u628a\u4e00\u4e2a Go \u670d\u52a1\u642d\u8d77\u6765&#xff0c;\u5230\u5e95\u8be5\u5efa\u54ea\u4e9b\u76ee\u5f55\u3001\u63a5\u53e3\u600e\u4e48\u5b9a\u3001\u9519\u8bef\u7801\u600e\u4e48\u7f16\u3001\u914d\u7f6e\u600e\u4e48\u653e\u3002\u8fd9\u4e00\u7bc7\u662f\u6574\u4e2a\u4e13\u680f\u7684\u5730\u57fa&#xff0c;\u540e\u9762\u6240\u6709\u5b9e\u6218\u9879\u76ee\u90fd\u6309\u8fd9\u5957\u9aa8\u67b6\u6765\u3002 \u70b9\u540d\u4e00\u4e0b\u53d7\u4f17&#xff1a;\u80fd\u5199 Go\u3001\u80fd\u8dd1\u901a Gin \u7684 CRUD&#xff0c;\u4f46\u6ca1\u4ece\u96f6\u642d\u8fc7\u4e00\u4e2a\u80fd\u88ab\u4e09\u4e2a\u4eba\u4ee5\u4e0a\u534f\u4f5c\u7684\u5de5\u7a0b\u9aa8\u67b6\u7684\u540c\u5b66\u3002\u5982\u679c\u4f60\u5df2\u7ecf\u5728","og_url":"https:\/\/www.wsisp.com\/helps\/117442.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-24T13:48:22+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117442.html","url":"https:\/\/www.wsisp.com\/helps\/117442.html","name":"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-24T13:48:22+00:00","dateModified":"2026-10-24T13:48:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117442.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117442.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117442.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Go \u9879\u76ee\u9aa8\u67b6 25 \u4e2a\u76ee\u5f55\u53ea\u7528 9 \u4e2a\uff1a\u9519\u8bef\u7801\u9519 1 \u4f4d\uff0c\u7ebf\u4e0a\u6392\u67e5\u591a\u82b1 3 \u5c0f\u65f6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117442"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117442\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117442"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}