{"id":205740,"date":"2025-06-12T12:26:47","date_gmt":"2025-06-12T04:26:47","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205740\/"},"modified":"2025-06-12T12:26:47","modified_gmt":"2025-06-12T04:26:47","slug":"golang%e6%a1%86%e6%9e%b6%e5%9c%a8%e4%b8%8d%e5%90%8c%e5%9c%ba%e6%99%af%e4%b8%8b%e7%9a%84%e4%bc%98%e7%bc%ba%e7%82%b9","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205740\/","title":{"rendered":"golang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9"},"content":{"rendered":"<p>GOLANG\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300agolang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01,<br \/>\n<br \/>,Go \u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u5448\u73b0\u51fa\u4f18\u52bf\u548c\u4e0d\u8db3\uff1aWeb \u5f00\u53d1\uff1a\u9ad8\u6027\u80fd\u3001\u53ef\u4f38\u7f29\u3001\u6613\u7528\uff0c\u4f46\u63d2\u4ef6\u8f83\u5c11\uff0c\u7ef4\u62a4\u6027\u968f\u7740\u590d\u6742\u5ea6\u589e\u52a0\u800c\u964d\u4f4e\u3002\u5e76\u53d1\u7f16\u7a0b\uff1a\u9ad8\u6548\u3001\u53ef\u9760\u3001\u6613\u7528\uff0c\u4f46\u8fc7\u5ea6\u5e76\u53d1\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u74f6\u9888\u548c\u8c03\u8bd5\u590d\u6742\u5ea6\u3002\u547d\u4ee4\u884c\u5de5\u5177\uff1a\u7b80\u5355\u3001\u53ef\u6269\u5c55\u3001\u53ef\u5b9a\u5236\uff0c\u4f46\u9ad8\u7ea7\u529f\u80fd\u6709\u9650\uff0c\u53ef\u80fd\u5f15\u5165\u4f9d\u8d56\u9879\u3002,<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729954767671d03cf91c51.jpg\" class=\"aligncenter\">,<br \/>\n<strong>Go \u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9<\/strong>,<br \/>\n<strong>\u6982\u8ff0<\/strong>,Go \u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u5957\u5de5\u5177\u548c\u5e93\uff0c\u7528\u4e8e\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u548c\u6613\u4e8e\u7ef4\u62a4\u7684 Go \u5e94\u7528\u7a0b\u5e8f\u3002\u6839\u636e\u4e0d\u540c\u7684\u573a\u666f\uff0cGo \u6846\u67b6\u5177\u6709\u72ec\u7279\u7684\u4f18\u7f3a\u70b9\u3002\u672c\u6587\u5c06\u63a2\u8ba8 Go \u6846\u67b6\u5728\u5e38\u89c1\u573a\u666f\u4e2d\u7684\u4f18\u52bf\u548c\u4e0d\u8db3\uff0c\u5e76\u63d0\u4f9b\u5b9e\u6218\u6848\u4f8b\u3002,<br \/>\n<strong>\u573a\u666f 1\uff1aWeb \u5f00\u53d1<\/strong>,<br \/>\n<strong>\u4f18\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong>,\u6784\u5efa\u4e00\u4e2a\u57fa\u4e8e echo \u6846\u67b6\u7684 REST API\u3002,<br \/>\n<strong>\u573a\u666f 2\uff1a\u5e76\u53d1\u7f16\u7a0b<\/strong>,<br \/>\n<strong>\u4f18\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong>,\u6784\u5efa\u4e00\u4e2a goroutine \u6c60\u6765\u5904\u7406\u5e76\u53d1\u8bf7\u6c42\u3002,<br \/>\n<strong>\u573a\u666f 3\uff1a\u547d\u4ee4\u884c\u5de5\u5177<\/strong>,<br \/>\n<strong>\u4f18\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u7f3a\u70b9\uff1a<\/strong>,<br \/>\n<strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong>,\u6784\u5efa\u4e00\u4e2a Cobra \u547d\u4ee4\u884c\u5de5\u5177\u6765\u7ba1\u7406\u7528\u6237\u3002,\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002,<br \/>\n<strong>\u53ef\u7ef4\u62a4\u6027\uff1a<\/strong> \u968f\u7740\u5e94\u7528\u7a0b\u5e8f\u7684\u590d\u6742\u5ea6\u589e\u52a0\uff0c\u7ef4\u62a4 Go Web \u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002,<br \/>\n<strong>\u63d2\u4ef6\u8f83\u5c11\uff1a<\/strong> \u4e0e\u5176\u4ed6\u8bed\u8a00\u7684\u6846\u67b6\u76f8\u6bd4\uff0cGo \u6846\u67b6\u7684\u63d2\u4ef6\u751f\u6001\u7cfb\u7edf\u76f8\u5bf9\u8f83\u5c0f\u3002,<br \/>\n<strong>\u53ef\u4f38\u7f29\u6027\uff1a<\/strong> Go \u4f7f\u7528\u5e76\u53d1\u6a21\u578b\uff0c\u5141\u8bb8\u6c34\u5e73\u6269\u5c55\u5e94\u7528\u7a0b\u5e8f\u4ee5\u6ee1\u8db3\u589e\u52a0\u7684\u8d1f\u8f7d\u3002,<br \/>\n<strong>\u9ad8\u6027\u80fd\uff1a<\/strong> Go \u6846\u67b6\u5982 Gorilla Mux \u548c echo \u53ef\u4ee5\u521b\u5efa\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u6709\u6548\u5904\u7406\u9ad8\u5e76\u53d1\u8bf7\u6c42\u3002,<br \/>\n<strong>\u6613\u4e8e\u4f7f\u7528\uff1a<\/strong> \u8fd9\u4e9b\u6846\u67b6\u63d0\u4f9b\u4e86\u7b80\u5355\u7684 API \u548c\u6587\u6863\uff0c\u7b80\u5316\u4e86 Web \u5f00\u53d1\u4efb\u52a1\u3002,GOLANG\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300agolang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01,<br \/>\n<b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>golang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9<\/span><\/p>\n<h1>golang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9<\/h1>\n<p><span>2024-10-26 22:59:44<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>GOLANG\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66\u4e60\u79ef\u7d2f\u77e5\u8bc6\uff0c\u73b0\u5c06\u5b66\u4e60\u5230\u7684\u77e5\u8bc6\u8bb0\u5f55\u4e00\u4e0b\uff0c\u4e5f\u662f\u5c06\u6211\u7684\u6240\u5f97\u5206\u4eab\u7ed9\u5927\u5bb6\uff01\u800c\u4eca\u5929\u8fd9\u7bc7\u6587\u7ae0\u300agolang\u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9\u300b\u5e26\u5927\u5bb6\u6765\u4e86\u89e3\u4e00\u4e0b##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><\/p>\n<p>Go \u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u5448\u73b0\u51fa\u4f18\u52bf\u548c\u4e0d\u8db3\uff1aWeb \u5f00\u53d1\uff1a\u9ad8\u6027\u80fd\u3001\u53ef\u4f38\u7f29\u3001\u6613\u7528\uff0c\u4f46\u63d2\u4ef6\u8f83\u5c11\uff0c\u7ef4\u62a4\u6027\u968f\u7740\u590d\u6742\u5ea6\u589e\u52a0\u800c\u964d\u4f4e\u3002\u5e76\u53d1\u7f16\u7a0b\uff1a\u9ad8\u6548\u3001\u53ef\u9760\u3001\u6613\u7528\uff0c\u4f46\u8fc7\u5ea6\u5e76\u53d1\u53ef\u80fd\u5bfc\u81f4\u6027\u80fd\u74f6\u9888\u548c\u8c03\u8bd5\u590d\u6742\u5ea6\u3002\u547d\u4ee4\u884c\u5de5\u5177\uff1a\u7b80\u5355\u3001\u53ef\u6269\u5c55\u3001\u53ef\u5b9a\u5236\uff0c\u4f46\u9ad8\u7ea7\u529f\u80fd\u6709\u9650\uff0c\u53ef\u80fd\u5f15\u5165\u4f9d\u8d56\u9879\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729954767671d03cf91c51.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Go \u6846\u67b6\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u4f18\u7f3a\u70b9<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>Go \u6846\u67b6\u63d0\u4f9b\u4e86\u4e00\u5957\u5de5\u5177\u548c\u5e93\uff0c\u7528\u4e8e\u6784\u5efa\u9ad8\u6548\u3001\u53ef\u6269\u5c55\u548c\u6613\u4e8e\u7ef4\u62a4\u7684 Go \u5e94\u7528\u7a0b\u5e8f\u3002\u6839\u636e\u4e0d\u540c\u7684\u573a\u666f\uff0cGo \u6846\u67b6\u5177\u6709\u72ec\u7279\u7684\u4f18\u7f3a\u70b9\u3002\u672c\u6587\u5c06\u63a2\u8ba8 Go \u6846\u67b6\u5728\u5e38\u89c1\u573a\u666f\u4e2d\u7684\u4f18\u52bf\u548c\u4e0d\u8db3\uff0c\u5e76\u63d0\u4f9b\u5b9e\u6218\u6848\u4f8b\u3002<\/p>\n<p><strong>\u573a\u666f 1\uff1aWeb \u5f00\u53d1<\/strong><\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong> Go \u6846\u67b6\u5982 Gorilla Mux \u548c echo \u53ef\u4ee5\u521b\u5efa\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u6709\u6548\u5904\u7406\u9ad8\u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<li><strong>\u53ef\u4f38\u7f29\u6027\uff1a<\/strong> Go \u4f7f\u7528\u5e76\u53d1\u6a21\u578b\uff0c\u5141\u8bb8\u6c34\u5e73\u6269\u5c55\u5e94\u7528\u7a0b\u5e8f\u4ee5\u6ee1\u8db3\u589e\u52a0\u7684\u8d1f\u8f7d\u3002<\/li>\n<li><strong>\u6613\u4e8e\u4f7f\u7528\uff1a<\/strong> \u8fd9\u4e9b\u6846\u67b6\u63d0\u4f9b\u4e86\u7b80\u5355\u7684 API \u548c\u6587\u6863\uff0c\u7b80\u5316\u4e86 Web \u5f00\u53d1\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u63d2\u4ef6\u8f83\u5c11\uff1a<\/strong> \u4e0e\u5176\u4ed6\u8bed\u8a00\u7684\u6846\u67b6\u76f8\u6bd4\uff0cGo \u6846\u67b6\u7684\u63d2\u4ef6\u751f\u6001\u7cfb\u7edf\u76f8\u5bf9\u8f83\u5c0f\u3002<\/li>\n<li><strong>\u53ef\u7ef4\u62a4\u6027\uff1a<\/strong> \u968f\u7740\u5e94\u7528\u7a0b\u5e8f\u7684\u590d\u6742\u5ea6\u589e\u52a0\uff0c\u7ef4\u62a4 Go Web \u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u6784\u5efa\u4e00\u4e2a\u57fa\u4e8e echo \u6846\u67b6\u7684 REST API\u3002<\/p>\n<pre>package main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"net\/http\"\n\n    \"github.com\/labstack\/echo\/v4\"\n)\n\n\/\/ \u5b9a\u4e49\u4e00\u4e2a\u7528\u4e8e\u5b58\u50a8\u6570\u636e\u7684\u7b80\u5355\u6a21\u578b\ntype Message struct {\n    Text string\n}\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684 echo \u8def\u7531 Handler\nfunc main() {\n    e := echo.New()\n\n    \/\/ \u5b9a\u4e49\u4e00\u4e2a\u8def\u7531\uff0c\u63a5\u6536 POST \u8bf7\u6c42\u5e76\u521b\u5efa\u6d88\u606f\n    e.POST(\"\/messages\", func(c echo.Context) error {\n        m := new(Message)\n        if err := c.Bind(m); err != nil {\n            return err\n        }\n        return c.JSON(http.StatusCreated, m)\n    })\n\n    \/\/ \u5b9a\u4e49\u4e00\u4e2a\u8def\u7531\uff0c\u63a5\u6536 GET \u8bf7\u6c42\u5e76\u83b7\u53d6\u6240\u6709\u6d88\u606f\n    e.GET(\"\/messages\", func(c echo.Context) error {\n        return c.JSON(http.StatusOK, []string{\"Hello\", \"World!\"})\n    })\n\n    \/\/ \u542f\u52a8\u670d\u52a1\u5668\n    if err := e.Start(context.Background(), \":8080\"); err != nil {\n        fmt.Println(\"Error starting server:\", err)\n    }\n}<\/pre>\n<p><strong>\u573a\u666f 2\uff1a\u5e76\u53d1\u7f16\u7a0b<\/strong><\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u9ad8\u6548\uff1a<\/strong> Go \u7684\u5185\u7f6e\u5e76\u53d1\u7279\u6027\u4f7f\u5f00\u53d1\u9ad8\u5e76\u53d1\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u9ad8\u6548\uff0c\u65e0\u9700\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3002<\/li>\n<li><strong>\u53ef\u9760\uff1a<\/strong> Go \u7684\u5e76\u53d1\u6a21\u578b\u63d0\u4f9b\u6545\u969c\u5b89\u5168\u673a\u5236\uff0c\u4f7f\u5176\u6210\u4e3a\u6784\u5efa\u5bb9\u9519\u7cfb\u7edf\u7684\u4e00\u4e2a\u53ef\u9760\u9009\u62e9\u3002<\/li>\n<li><strong>\u6613\u4e8e\u4f7f\u7528\uff1a<\/strong> Goroutine \u548c channel \u7b49\u5e76\u53d1\u539f\u8bed\u4f7f\u5f00\u53d1\u5e76\u53d1\u5e94\u7528\u7a0b\u5e8f\u53d8\u5f97\u7b80\u5355\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u6027\u80fd\u74f6\u9888\uff1a<\/strong> \u5982\u679c\u5e76\u53d1\u8fc7\u5ea6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u548c\u6b7b\u9501\u3002<\/li>\n<li><strong>\u8c03\u8bd5\u590d\u6742\uff1a<\/strong> \u8c03\u8bd5\u5e76\u53d1\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5177\u6709\u6311\u6218\u6027\uff0c\u56e0\u4e3a\u5b83\u6d89\u53ca\u591a\u4e2a\u7ebf\u7a0b\u548c\u5171\u4eab\u8d44\u6e90\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u6784\u5efa\u4e00\u4e2a goroutine \u6c60\u6765\u5904\u7406\u5e76\u53d1\u8bf7\u6c42\u3002<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"sync\"\n)\n\n\/\/ \u5b9a\u4e49\u4e00\u4e2a goroutine \u6c60\ntype Pool struct {\n    Wg sync.WaitGroup\n    Cap int\n}\n\n\/\/ \u65b0\u5efa\u4e00\u4e2a goroutine \u6c60\nfunc NewPool(cap int) *Pool {\n    return &amp;Pool{\n        Cap: cap,\n    }\n}\n\n\/\/ \u5411\u6c60\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u4efb\u52a1\nfunc (p *Pool) Add(f func()) {\n    p.Wg.Add(1)\n    go func() {\n        defer p.Wg.Done()\n        f()\n    }()\n}\n\n\/\/ \u7b49\u5f85\u6240\u6709\u4efb\u52a1\u5b8c\u6210\nfunc (p *Pool) Wait() {\n    p.Wg.Wait()\n}\n\n\/\/ \u4f7f\u7528 goroutine \u6c60\u5904\u7406\u8bf7\u6c42\nfunc main() {\n    p := NewPool(10)\n    for i := 0; i &lt; 100; i++ {\n        p.Add(func() {\n            fmt.Println(\"\u4efb\u52a1\", i)\n        })\n    }\n    p.Wait()\n}<\/pre>\n<p><strong>\u573a\u666f 3\uff1a\u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/p>\n<p><strong>\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u7b80\u5355\u6027\uff1a<\/strong> Go \u6846\u67b6\u5982 Cobra \u4e3a\u5f00\u53d1\u547d\u4ee4\u884c\u5de5\u5177\u63d0\u4f9b\u4e86\u7b80\u5355\u7b80\u6d01\u7684\u63a5\u53e3\u3002<\/li>\n<li><strong>\u53ef\u6269\u5c55\u6027\uff1a<\/strong> Cobra \u5141\u8bb8\u901a\u8fc7\u63d2\u4ef6\u6269\u5c55\u547d\u4ee4\u884c\u5de5\u5177\u7684\u529f\u80fd\u3002<\/li>\n<li><strong>\u53ef\u5b9a\u5236\u6027\uff1a<\/strong> Go \u6846\u67b6\u4e3a\u547d\u4ee4\u884c\u5de5\u5177\u7684\u9ad8\u7ea7\u5b9a\u5236\u63d0\u4f9b\u4e86\u5f88\u591a\u7075\u6d3b\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u9ad8\u7ea7\u529f\u80fd\u6709\u9650\uff1a<\/strong> Go \u6846\u67b6\u5bf9\u4e8e\u9700\u8981\u9ad8\u7ea7\u529f\u80fd\uff08\u4f8b\u5982\u547d\u4ee4\u5386\u53f2\u8bb0\u5f55\u548c\u81ea\u52a8\u8865\u5168\uff09\u7684\u547d\u4ee4\u884c\u5de5\u5177\u6765\u8bf4\u53ef\u80fd\u4e0d\u591f\u3002<\/li>\n<li><strong>\u4f9d\u8d56\u95ee\u9898\uff1a<\/strong> \u4f7f\u7528 Go \u6846\u67b6\u6765\u6784\u5efa\u547d\u4ee4\u884c\u5de5\u5177\u53ef\u80fd\u4f1a\u5f15\u5165\u4f9d\u8d56\u9879\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u6784\u5efa\u4e00\u4e2a Cobra \u547d\u4ee4\u884c\u5de5\u5177\u6765\u7ba1\u7406\u7528\u6237\u3002<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n\n    \"github.com\/spf13\/cobra\"\n)\n\n\/\/ \u5b9a\u4e49\u6839\u547d\u4ee4\nvar rootCmd = &amp;cobra.Command{\n    Use: \"user-manager\",\n}\n\n\/\/ \u5b9a\u4e49\u5b50\u547d\u4ee4\uff1a\u521b\u5efa\u3001\u66f4\u65b0\u548c\u5220\u9664\u7528\u6237\nvar createCmd = &amp;cobra.Command{\n    Use:   \"create\",\n    Short: \"Create a new user\",\n    Run: func(cmd *cobra.Command, args []string) {\n        fmt.Println(\"Creating a new user\")\n    },\n}\n\nvar updateCmd = &amp;cobra.Command{\n    Use:   \"update\",\n    Short: \"Update an existing user\",\n    Run: func(cmd *cobra.Command, args []string) {\n        fmt.Println(\"Updating an existing user\")\n    },\n}\n\nvar deleteCmd = &amp;cobra.Command{\n    Use:   \"delete\",\n    Short: \"Delete an existing user\",\n    Run: func(cmd *cobra.Command, args []string) {\n        fmt.Println(\"Deleting an existing user\")\n    },\n}\n\nfunc main() {\n    rootCmd.AddCommand(createCmd, updateCmd, deleteCmd)\n    rootCmd.Execute()\n}<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301GOLANG\uff01\u66f4\u591a\u5173\u4e8eGOLANG\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8GOLANG\u516c\u4f17\u53f7\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   PHP\u51fd\u6570\u5982\u4f55\u5904\u7406\u9519\u8bef\u53c2\u6570\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   Java\u51fd\u6570\u4f18\u52a3\u52bf\u5168\u65b9\u4f4d\u8003\u91cf\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>GOLANG\u5c0f\u767d\u4e00\u679a\uff0c\u6b63\u5728\u4e0d\u65ad\u5b66&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205740","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205740"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205740\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}