{"id":10021320,"date":"2026-03-19T14:40:54","date_gmt":"2026-03-19T06:40:54","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021320"},"modified":"2026-03-19T14:40:54","modified_gmt":"2026-03-19T06:40:54","slug":"go-%e5%90%8e%e7%ab%af%e5%bc%80%e5%8f%91%e5%bf%85%e7%9f%a5%e7%9a%84-10-%e6%9d%a1%e6%9c%80%e4%bd%b3%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021320","title":{"rendered":"Go \u540e\u7aef\u5f00\u53d1\u5fc5\u77e5\u7684 10 \u6761\u6700\u4f73\u5b9e\u8df5"},"content":{"rendered":"<p>Go \u5df2\u7ecf\u6210\u4e3a\u6784\u5efa\u9ad8\u53ef\u6269\u5c55\u540e\u7aef\u670d\u52a1\u3001\u4e91\u539f\u751f\u5e94\u7528\u548c DevOps \u5de5\u5177\u7684\u9996\u9009\u8bed\u8a00\u4e4b\u4e00\u3002\u5b83\u7684\u7b80\u6d01\u662f\u6700\u5927\u4f18\u52bf\uff0c\u4f46\u5199\u51fa\u771f\u6b63\u80fd\u4e0a\u751f\u4ea7\u3001\u597d\u7ef4\u62a4\u7684 Go \u4ee3\u7801\uff0c\u8fdc\u4e0d\u6b62\u638c\u63e1\u8bed\u6cd5\u8fd9\u4e48\u7b80\u5355\u3002<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u63d0\u70bc\u4e86\u5927\u91cf\u56e2\u961f\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u9a8c\u8bc1\u8fc7\u7684\u5b9e\u7528\u505a\u6cd5\uff0c\u8986\u76d6\u5de5\u5177\u94fe\u3001\u4ee3\u7801\u7ec4\u7ec7\u3001\u9519\u8bef\u5904\u7406\u3001\u65e5\u5fd7\u3001\u6d4b\u8bd5\u7b49\u65b9\u9762\uff0c\u5e2e\u52a9\u4f60\u5199\u51fa\u66f4\u5e72\u51c0\u3001\u66f4\u4e00\u81f4\u3001\u66f4\u5bb9\u6613\u534f\u4f5c\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5982\u679c\u4f60\u662f Go \u65b0\u624b\uff0c\u5efa\u8bae\u5148\u770b<a href=\"https:\/\/link.segmentfault.com\/?enc=kkCaGC%2BAPGLPaHGaTh07Rw%3D%3D.GiXute2aGQ1FoKNCk%2BjU5G3DfvyR5u9RivqvQTt%2BVas%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5b98\u65b9\u6587\u6863<\/a> \u548c <a href=\"https:\/\/link.segmentfault.com\/?enc=AZRAo7Nng88HdaZwCWkPTQ%3D%3D.PrEC%2FIqsVSQze4hZl%2BOhB6u%2FIAIKlDqDnuEPXj9bEtM%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Effective Go<\/a>\uff0c\u672c\u6587\u662f\u5728\u8fd9\u4e9b\u57fa\u7840\u4e4b\u4e0a\uff0c\u9488\u5bf9\u4e2d\u5927\u578b\u56e2\u961f\u5e38\u89c1\u75db\u70b9\u7ed9\u51fa\u7684\u8fdb\u9636\u5efa\u8bae\u3002<\/p>\n<p><img decoding=\"async\"   referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000047663069\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" title=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\"><\/p>\n<h2>1. \u5de5\u5177\u94fe\uff1a\u7b2c\u4e00\u9053\u9632\u7ebf<\/h2>\n<h3>\u683c\u5f0f\u5316\u4e0e Lint<\/h3>\n<p>\u534f\u4f5c\u9879\u76ee\u91cc\uff0c\u4ee3\u7801\u98ce\u683c\u7edf\u4e00\u975e\u5e38\u91cd\u8981\u3002Go \u81ea\u5e26\u795e\u5668\uff1a<\/p>\n<ul>\n<li><strong>gofmt<\/strong>\uff1a\u6c38\u8fdc\u7528 gofmt \u683c\u5f0f\u5316\u4ee3\u7801\uff0c\u5f7b\u5e95\u6d88\u706d\u201c\u7f29\u8fdb\u7528 tab \u8fd8\u662f\u7a7a\u683c\u201d\u4e4b\u7c7b\u7684\u65e0\u8c13\u4e89\u8bba\u3002<\/li>\n<li><strong>golangci-lint<\/strong>\uff1a\u5f3a\u70c8\u63a8\u8350\u4f7f\u7528 <a href=\"https:\/\/link.segmentfault.com\/?enc=i%2FgW5n0Ebpn8P%2BCVGCzGxg%3D%3D.Xp%2Fd7PeKF1VduRjbr72IRCxMyVXCrG9uqA2jFPWXVZBtNbmRvoMtqC%2FOn%2Foc%2BE6G\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">golangci-lint<\/a>\uff0c\u5b83\u96c6\u6210\u4e86\u51e0\u5341\u4e2a linter\u3002<strong>CI \u5fc5\u987b\u5728 lint \u5931\u8d25\u65f6\u76f4\u63a5\u7ea2\u7ebf<\/strong>\uff0c\u628a\u95ee\u9898\u627c\u6740\u5728 code review \u4e4b\u524d\u3002<\/li>\n<\/ul>\n<h3>Mock \u751f\u6210<\/h3>\n<p>\u7528 <code>go:generate<\/code> + <code>mockgen<\/code> \u81ea\u52a8\u751f\u6210 mock\u3002Makefile \u91cc\u52a0\u4e00\u4e2a generate\/mock \u7684 target\uff0c\u8ba9\u5927\u5bb6\u4e00\u952e\u4fdd\u6301\u63a5\u53e3\u548c mock \u540c\u6b65\u3002<\/p>\n<h2>2. \u4ee3\u7801\u7ec4\u7ec7\uff1a\u7ed3\u6784\u51b3\u5b9a\u6e05\u6670\u5ea6<\/h2>\n<h3>\u4ed3\u5e93\u7ed3\u6784<\/h3>\n<p>\u5f3a\u70c8\u5efa\u8bae\u9075\u5faa\u793e\u533a\u516c\u8ba4\u7684 <strong><a href=\"https:\/\/link.segmentfault.com\/?enc=XqthAI2WShMsahwyBV3tzA%3D%3D.%2BJpUKIj0kUHF7EnAiPg4UX7nBFdKudRam8qpm9Vsjy%2BsCnknD7nkm5LucbOAsHpeSlJqGQ2DQKQ6Z3hPpYL%2FBg%3D%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Standard Go Project Layout<\/a><\/strong>\u3002\u65b0\u540c\u5b66 clone \u4e0b\u6765\u5c31\u80fd\u5feb\u901f\u4e0a\u624b\uff0c\u77e5\u9053 cmd\u3001internal\u3001pkg\u3001api \u7b49\u76ee\u5f55\u5206\u522b\u653e\u4ec0\u4e48\u3002<\/p>\n<h3>import \u987a\u5e8f<\/h3>\n<p>import \u8bed\u53e5\u8981\u5206\u7ec4\u4e14\u6709\u5e8f\uff1a<\/p>\n<ol>\n<li>\u6807\u51c6\u5e93<\/li>\n<li>\u7b2c\u4e09\u65b9\u5e93<\/li>\n<li>\u516c\u53f8\/\u7ec4\u7ec7\u5185\u90e8\u5e93<\/li>\n<li>\u672c\u9879\u76ee\u5185\u90e8\u5305<\/li>\n<\/ol>\n<p>\u274c \u4e71\u5e8f\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"Go\">import (\n    &quot;context&quot;\n    &quot;github.com\/sirupsen\/logrus&quot;\n    &quot;github.company.com\/org\/repo\/gapi&quot;\n    &quot;time&quot;\n    gdocs &quot;google.golang.org\/api\/docs\/v1&quot;\n)<\/code><\/pre>\n<p>\u2705 \u63a8\u8350\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">import (\n    &quot;context&quot;\n    &quot;time&quot;\n\n    &quot;github.com\/sirupsen\/logrus&quot;\n    gdocs &quot;google.golang.org\/api\/docs\/v1&quot;\n\n    &quot;github.company.com\/org\/repo\/gapi&quot;\n    &quot;github.company.com\/org\/repo\/snow&quot;\n    &quot;github.company.com\/org\/repo\/internal\/clients\/slack&quot;\n)<\/code><\/pre>\n<h3>\u5355\u4e2a\u6587\u4ef6\u5185\u7684\u4ee3\u7801\u5e03\u5c40<\/h3>\n<p>\u4e00\u4e2a \u3002go \u6587\u4ef6\u5efa\u8bae\u6309\u4ee5\u4e0b\u987a\u5e8f\u7ec4\u7ec7\uff08\u517b\u6210\u4e60\u60ef\u540e\u9605\u8bfb\u548c review \u6548\u7387\u4f1a\u660e\u663e\u63d0\u5347\uff09\uff1a<\/p>\n<ol>\n<li>const \/ var \u5b9a\u4e49<\/li>\n<li>struct \/ interface \u5b9a\u4e49<\/li>\n<li>\u5bfc\u51fa\u7684\uff08\u5927\u5199\uff09\u65b9\u6cd5<\/li>\n<li>\u975e\u5bfc\u51fa\u7684\uff08\u5c0f\u5199\uff09\u65b9\u6cd5<\/li>\n<li>\u8f85\u52a9\u51fd\u6570<\/li>\n<\/ol>\n<h2>4. \u547d\u540d\uff1a\u7b80\u5355\u3001\u4e0d\u5197\u4f59<\/h2>\n<p>\u5305\u540d\u5df2\u7ecf\u63d0\u4f9b\u4e86\u4e0a\u4e0b\u6587\uff0c\u5c31\u4e0d\u8981\u5728\u7c7b\u578b\u540d\u91cc\u91cd\u590d\u3002<\/p>\n<p>\u274c \u5197\u4f59\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">type DeploymentTransformerHandlerIntf interface{}\ntype DeploymentTransformerHandler struct{}<\/code><\/pre>\n<p>\u2705 \u7b80\u6d01\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">type DeploymentTransformerIntf interface{}\ntype DeploymentTransformer struct{}<\/code><\/pre>\n<p>\u201cHandler\u201d\u5728\u8fd9\u91cc\u5c31\u662f\u7eaf\u566a\u97f3\uff0c\u5f92\u589e\u9605\u8bfb\u8d1f\u62c5\u3002<\/p>\n<h2>5. Context\uff1a\u4f20\u53c2\uff0c\u4e0d\u8981\u585e\u7ed3\u6784\u4f53<\/h2>\n<p><strong>\u6c38\u8fdc\u628a context.Context \u4f5c\u4e3a\u51fd\u6570\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f20\u5165<\/strong>\uff0c\u800c\u4e0d\u662f\u585e\u5230 struct \u5b57\u6bb5\u91cc\u3002\u8fd9\u6837\u624d\u80fd\u6b63\u786e\u4f20\u64ad\u53d6\u6d88\u4fe1\u53f7\u548c\u8d85\u65f6\u3002<\/p>\n<p>\u274c \u9519\u8bef\u505a\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">type Client struct {\n    ctx context.Context\n}\n\nfunc (c *Client) DoSomething(foo string) {\n    \/\/ \u7528 c.ctx \u2014\u2014 \u5343\u4e07\u522b\u8fd9\u6837\uff01\n}<\/code><\/pre>\n<p>\u2705 \u6b63\u786e\u505a\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">func (c *Client) DoSomething(ctx context.Context, foo string) {\n    \/\/ \u7528 ctx\n}<\/code><\/pre>\n<p><strong>\u94c1\u5f8b<\/strong>\uff1a\u53ea\u8981\u65b9\u6cd5\u9700\u8981 context\uff0c\u4e00\u5f8b\u653e\u5728\u7b2c\u4e00\u4e2a\u53c2\u6570\u3002<\/p>\n<h2>6. \u65b9\u6cd5\u7b7e\u540d\uff1a\u62e5\u62b1\u51fd\u6570\u9009\u9879\u6a21\u5f0f\uff08Functional Options\uff09<\/h2>\n<p>\u53c2\u6570\u4e00\u591a\u5c31\u707e\u96be\u3002\u63a8\u8350\u4f7f\u7528\u51fd\u6570\u9009\u9879\u6a21\u5f0f\uff0c\u65e2\u53ef\u8bfb\u53c8\u7075\u6d3b\u3002<\/p>\n<p>\u274c \u707e\u96be\u7b7e\u540d\uff1a<\/p>\n<pre><code class=\"Go\">svr := server.New(&quot;localhost&quot;, 8080, time.Minute, 120)<\/code><\/pre>\n<p>\u8c01\u77e5\u9053 time.Minute \u548c 120 \u5206\u522b\u662f\u4ec0\u4e48\uff1f<\/p>\n<p>\u2705 \u81ea\u89e3\u91ca\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"Go\">svr := server.New(\n    server.WithHost(&quot;localhost&quot;),\n    server.WithPort(8080),\n    server.WithTimeout(time.Minute),\n    server.WithMaxConn(120),\n)<\/code><\/pre>\n<p>\u540e\u7eed\u52a0\u53c2\u6570\u4e5f\u4e0d\u7834\u574f\u5df2\u6709\u8c03\u7528\uff0c\u6269\u5c55\u6027\u6781\u5f3a\u3002<\/p>\n<h2>7. \u9519\u8bef\u5904\u7406\uff1a\u4e0a\u4e0b\u6587\u624d\u662f\u738b\u9053<\/h2>\n<h3>\u7528\u5806\u6808 + \u9519\u8bef\u5305\u88c5<\/h3>\n<p>\u63a8\u8350\u4f7f\u7528 <code>github.com\/pingcap\/errors<\/code>\u3001<code>go.uber.org\/multierr<\/code> \u6216\u7c7b\u4f3c\u5e93\uff08\u6216\u81ea\u5df1\u5c01\u88c5 yerrors\uff09\uff0c\u7ed9\u9519\u8bef\u81ea\u52a8\u5e26\u4e0a\u8c03\u7528\u6808\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\uff1f<\/strong> \u624b\u52a8\u5728\u5b57\u7b26\u4e32\u91cc\u5199\u201c\u5728 xxx \u65b9\u6cd5\u91cc\u51fa\u9519\u201d\u7ef4\u62a4\u6210\u672c\u6781\u9ad8\u4e14\u5bb9\u6613\u6f0f\uff0c\u5806\u6808\u4e00\u6b21\u89e3\u51b3\u3002<\/p>\n<p><strong>\u5b89\u5168\u7ea2\u7ebf<\/strong>\uff1a\u5806\u6808\u4fe1\u606f\u53ea\u5199\u65e5\u5fd7\uff0c<strong>\u7edd\u4e0d<\/strong>\u8fd4\u56de\u7ed9 API \u8c03\u7528\u65b9\uff08\u6cc4\u9732\u5b9e\u73b0\u7ec6\u8282\u662f\u5b89\u5168\u6f0f\u6d1e\uff09\u3002<\/p>\n<h3>\u65e5\u5fd7\u7ea7\u522b\u8981\u5206\u6e05<\/h3>\n<ul>\n<li><strong>Error<\/strong> \u7ea7\u522b\uff1a\u53ea\u7528\u4e8e\u771f\u6b63\u7684\u670d\u52a1\u5185\u90e8\u9519\u8bef\uff08500 \u573a\u666f\uff09<\/li>\n<li><strong>Warn<\/strong> \u7ea7\u522b\uff1a\u7528\u6237\/\u5ba2\u6237\u7aef\u7684\u9519\u8bef\uff08400 \u573a\u666f\uff09<\/li>\n<\/ul>\n<h3>\u9519\u8bef\u53ea\u5728\u9876\u5c42 log \u4e00\u6b21<\/h3>\n<p>\u5c42\u5c42 log \u540c\u4e00\u4e2a\u9519\u8bef\u662f\u53cd\u6a21\u5f0f\u3002<\/p>\n<p>\u274c \u5c42\u5c42\u91cd\u590d log\uff1a<\/p>\n<pre><code class=\"Go\">if err != nil {\n    log.Errorf(&quot;ERROR :: Google Docs :: NewGoogleApiHandler :: Unable to create service :: %v&quot;, err)\n    return nil, err\n}<\/code><\/pre>\n<p>\u2705 \u4f18\u96c5\u5305\u88c5\u5411\u4e0a\u900f\u4f20\uff1a<\/p>\n<pre><code class=\"Go\">if err != nil {\n    return nil, fmt.Errorf(&quot;failed to create google docs service: %w&quot;, err)\n    \/\/ \u6216\u7528 errors.Wrap \/ yerrors.Errorf\n}<\/code><\/pre>\n<p>\u9876\u5c42\u7edf\u4e00 log + \u5e26\u6808\uff0c\u5e72\u51c0\u53c8\u597d debug\u3002<\/p>\n<h2>8. \u65e5\u5fd7\uff1a\u7ed3\u6784\u5316 &gt; \u5b57\u7b26\u4e32\u62fc\u63a5<\/h2>\n<p>\u63a8\u8350\u7528 <strong>zap<\/strong> \u6216 <strong>logrus<\/strong>\uff08\u751f\u4ea7\u73af\u5883\u5f00 JSON \u683c\u5f0f\uff09\u3002<\/p>\n<h3>\u7ed3\u6784\u5316\u65e5\u5fd7\u793a\u4f8b<\/h3>\n<p>\u274c \u5b57\u7b26\u4e32\u62fc\u63a5\uff1a<\/p>\n<pre><code class=\"Go\">log.Errorf(&quot;Failed to write summary. Error: %s&quot;, err)<\/code><\/pre>\n<p>\u2705 \u7ed3\u6784\u5316\uff1a<\/p>\n<pre><code class=\"Go\">log.WithFields(log.Fields{\n    &quot;event&quot;: event,\n    &quot;topic&quot;: topic,\n    &quot;key&quot;:   key,\n}).Info(&quot;processing new event&quot;)<\/code><\/pre>\n<p>\u7ed3\u6784\u5316\u65e5\u5fd7\u5728 ELK \/ Loki \/ \u963f\u91cc\u4e91 SLS \u7b49\u5e73\u53f0\u4e0a\u641c\u7d22\u3001\u544a\u8b66\u6548\u7387\u9ad8\u51fa\u51e0\u4e2a\u91cf\u7ea7\u3002<\/p>\n<h3>\u53ef\u5ffd\u7565\u7684\u5df2\u77e5\u9519\u8bef\u6253 Debug<\/h3>\n<pre><code class=\"Go\">if err != nil {\n    if errors.Is(err, ErrUserAlreadyExists) {  \/\/ \u6216 err.Error() == &quot;user_exists&quot;\n        log.WithError(err).Debug(&quot;user exists, continuing&quot;)\n        return nil \/\/ \u6216 continue\n    }\n    return nil, fmt.Errorf(&quot;failed to add user %s: %w&quot;, userID, err)\n}<\/code><\/pre>\n<h3>\u8bf7\u6c42\u7ea7\u65e5\u5fd7\uff08\u5e26 trace id\uff09<\/h3>\n<p>\u7528\u51fd\u6570\u5f0f Logger \u6ce8\u5165\uff1a<\/p>\n<pre><code class=\"Go\">type Handler struct {\n    LoggerFn func(ctx context.Context) *logrus.Entry\n}\n\nfunc (h *Handler) CheckHealth(ctx context.Context) {\n    logger := h.LoggerFn(ctx)\n    logger.Info(&quot;health check started&quot;)\n}<\/code><\/pre>\n<p>\u4e2d\u95f4\u4ef6\u53ef\u4ee5\u628a request-id \/ trace-id \u585e\u8fdb context\uff0c\u81ea\u52a8\u5e26\u5230\u6240\u6709\u65e5\u5fd7\u91cc\uff0c\u5b9e\u73b0\u5168\u94fe\u8def\u8ffd\u8e2a\u3002<\/p>\n<h2>9. HTTP \u8c03\u7528\uff1a\u4f18\u5148\u7528 Context \u8d85\u65f6<\/h2>\n<p>\u4e0d\u8981\u4f9d\u8d56 http.Client \u7684\u5168\u5c40 Timeout\uff0c\u7528 context \u63a7\u5236\u66f4\u7cbe\u7ec6\u3002<\/p>\n<pre><code class=\"Go\">ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\n\nreq, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\nresp, err := client.Do(req)<\/code><\/pre>\n<p>\u8fd9\u6837\u80fd\u66f4\u597d\u5730\u914d\u5408\u4e0a\u5c42\u8d85\u65f6\u548c\u53d6\u6d88\u4f20\u64ad\u3002<\/p>\n<h2>10. \u5355\u5143\u6d4b\u8bd5\uff1a\u8868\u9a71\u52a8\u6d4b\u8bd5\u624d\u662f\u738b\u9053<\/h2>\n<h3>\u63a8\u8350\u5de5\u5177<\/h3>\n<ul>\n<li>\n<p><strong>testify<\/strong>\uff1aassert\u3001require\u3001mock \u7b49\u90fd\u5f88\u65b9\u4fbf<\/p>\n<ul>\n<li><code>assert.EqualValues<\/code>\uff08map\/slice \u5ffd\u7565\u987a\u5e8f\uff09<\/li>\n<li><code>assert.EqualError<\/code>\uff08\u7b80\u5355\u9519\u8bef\u6bd4\u8f83\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u8868\u9a71\u52a8\u6d4b\u8bd5\u6a21\u677f<\/h3>\n<pre><code class=\"Go\">func TestToUpper(t *testing.T) {\n    tests := []struct {\n        name     string\n        input    string\n        expected string\n        wantErr  bool\n    }{\n        {\n            name:     &quot;\u6b63\u5e38\u8f93\u5165&quot;,\n            input:    &quot;hello&quot;,\n            expected: &quot;HELLO&quot;,\n            wantErr:  false,\n        },\n        {\n            name:     &quot;\u7a7a\u5b57\u7b26\u4e32&quot;,\n            input:    &quot;&quot;,\n            expected: &quot;&quot;,\n            wantErr:  true,\n        },\n    }\n\n    for _, tt := range tests {\n        t.Run(tt.name, func(t *testing.T) {\n            got, err := ToUpper(tt.input)\n            if tt.wantErr {\n                assert.Error(t, err)\n                return\n            }\n            assert.NoError(t, err)\n            assert.Equal(t, tt.expected, got)\n        })\n    }\n}<\/code><\/pre>\n<p><strong>\u6838\u5fc3\u539f\u5219<\/strong>\uff1a<\/p>\n<ul>\n<li>\u6d4b\u8bd5\u7528\u4f8b\u81ea\u5df1\u5e26 mock \u548c\u9884\u671f<\/li>\n<li>\u5faa\u73af\u4f53\u53ea\u8c03\u7528\u88ab\u6d4b\u4ee3\u7801 + \u65ad\u8a00\uff0c\u4e0d\u8981\u5199\u989d\u5916\u903b\u8f91<\/li>\n<li>\u5c3d\u91cf\u907f\u514d gomock \u7684 Any()\uff0c\u663e\u5f0f\u6307\u5b9a\u66f4\u5b89\u5168<\/li>\n<\/ul>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5199\u51fa\u751f\u4ea7\u7ea7\u7684 Go \u4ee3\u7801\uff0c\u6838\u5fc3\u4e0d\u662f\u201c\u80fd\u8dd1\u201d\uff0c\u800c\u662f\u201c\u597d\u7ef4\u62a4\u3001\u597d debug\u3001\u597d\u534f\u4f5c\u201d\u3002<\/p>\n<p>\u91c7\u7528\u8fd9\u4e9b\u5b9e\u8df5\uff0c\u4f60\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u7edf\u4e00\u683c\u5f0f\u548c\u7ec4\u7ec7\u964d\u4f4e\u8ba4\u77e5\u8d1f\u62c5<\/li>\n<li>\u901a\u8fc7\u9519\u8bef\u5305\u88c5 + \u7ed3\u6784\u5316\u65e5\u5fd7\u6781\u5927\u63d0\u9ad8\u95ee\u9898\u5b9a\u4f4d\u901f\u5ea6<\/li>\n<li>\u901a\u8fc7\u8868\u9a71\u52a8\u6d4b\u8bd5 + \u51fd\u6570\u9009\u9879\u8ba9\u4ee3\u7801\u66f4\u5065\u58ee\u3001\u66f4\u6613\u6269\u5c55<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u4e0d\u662f\u6559\u6761\uff0c\u800c\u662f\u5927\u91cf\u56e2\u961f\u5728\u89c4\u6a21\u5316\u8fc7\u7a0b\u4e2d\u8e29\u5751\u540e\u603b\u7ed3\u51fa\u7684\u201c\u6b62\u8840\u70b9\u201d\u3002\u53ef\u4ee5\u4ece\u4f60\u5f53\u524d\u6700\u75db\u7684\u70b9\u5f00\u59cb\u9010\u6b65\u843d\u5730\u3002<\/p>\n<p>\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u4f60\u56e2\u961f\u6b63\u5728\u7528\u7684 Go \u6700\u4f73\u5b9e\u8df5\uff5e<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047663067\">https:\/\/segmentfault.com\/a\/1190000047663067<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go \u5df2\u7ecf\u6210\u4e3a\u6784\u5efa\u9ad8\u53ef\u6269\u5c55\u540e\u7aef\u670d\u52a1\u3001\u4e91\u539f\u751f\u5e94\u7528\u548c DevOps \u5de5\u5177\u7684\u9996\u9009\u8bed\u8a00\u4e4b\u4e00\u3002\u5b83\u7684\u7b80\u6d01\u662f\u6700\u5927\u4f18\u52bf\uff0c\u4f46\u5199\u51fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021320","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021320"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021320\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}