{"id":86805,"date":"2020-05-15T20:54:44","date_gmt":"2020-05-15T12:54:44","guid":{"rendered":"http:\/\/4563.org\/?p=86805"},"modified":"2020-05-15T20:54:44","modified_gmt":"2020-05-15T12:54:44","slug":"%e5%88%86%e4%ba%ab%e4%b8%80%e6%ac%be%e9%80%82%e5%90%88%e4%ba%8e%e5%bf%ab%e9%80%9f%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e7%9a%84-go-%e6%a1%86%e6%9e%b6%ef%bc%8c%e5%8f%af%e7%94%a8%e4%ba%8e%e5%bc%80","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=86805","title":{"rendered":"\u5206\u4eab\u4e00\u6b3e\u9002\u5408\u4e8e\u5feb\u901f\u5f00\u53d1\u4e1a\u52a1\u7684 Go \u6846\u67b6\uff0c\u53ef\u7528\u4e8e\u5f00\u53d1 API \u670d\u52a1\uff0c\u9075\u5faa SOLID \u539f\u5219"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5206\u4eab\u4e00\u6b3e\u9002\u5408\u4e8e\u5feb\u901f\u5f00\u53d1\u4e1a\u52a1\u7684 Go \u6846\u67b6\uff0c\u53ef\u7528\u4e8e\u5f00\u53d1 API \u670d\u52a1\uff0c\u9075\u5faa SOLID \u539f\u5219               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qloog <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u6b3e\u9002\u5408\u4e8e\u5feb\u901f\u5f00\u53d1\u4e1a\u52a1\u7684 Go \u6846\u67b6\uff0c\u4e3b\u8981\u662f\u63d0\u4f9b API \u670d\u52a1\u3002<\/p>\n<h2>\u9879\u76ee\u5730\u5740<\/h2>\n<p>https:\/\/github.com\/1024casts\/snake<\/p>\n<h2>\u6280\u672f\u6808<\/h2>\n<ul>\n<li>\u6846\u67b6\u8def\u7531\u4f7f\u7528 gin \u8def\u7531<\/li>\n<li>\u4e2d\u95f4\u4ef6\u4f7f\u7528 gin \u6846\u67b6\u7684\u4e2d\u95f4\u4ef6<\/li>\n<li>\u6570\u636e\u5e93\u7ec4\u4ef6 gorm<\/li>\n<li>\u6587\u6863\u4f7f\u7528 swagger \u751f\u6210<\/li>\n<li>\u914d\u7f6e\u6587\u4ef6\u89e3\u6790\u5e93 viper<\/li>\n<li>\u4f7f\u7528 JWT \u8fdb\u884c\u8eab\u4efd\u9274\u6743\u8ba4\u8bc1<\/li>\n<li>\u6821\u9a8c\u5668 validator \u4e5f\u662f gin \u6846\u67b6\u9ed8\u8ba4\u7684\u6821\u9a8c\u5668\uff0c\u5f53\u524d\u6700\u65b0\u662f v9 \u7248\u672c<\/li>\n<li>\u4efb\u52a1\u8c03\u5ea6 cron<\/li>\n<li>\u5305\u7ba1\u7406\u5de5\u5177 go module<\/li>\n<li>\u6d4b\u8bd5\u6846\u67b6 goConvey<\/li>\n<li>CI\/CD Github Actions<\/li>\n<\/ul>\n<h2>\u7279\u6027<\/h2>\n<ul>\n<li>\u9075\u5faa RESTful API \u8bbe\u8ba1\u89c4\u8303<\/li>\n<li>\u57fa\u4e8e GIN WEB \u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e2d\u95f4\u4ef6\u652f\u6301\uff08\u7528\u6237\u8ba4\u8bc1\u3001\u8de8\u57df\u3001\u8bbf\u95ee\u65e5\u5fd7\u3001\u8bf7\u6c42\u9891\u7387\u9650\u5236\u3001\u8ffd\u8e2a ID \u7b49\uff09<\/li>\n<li>\u57fa\u4e8e GORM \u7684\u6570\u636e\u5e93\u5b58\u50a8<\/li>\n<li>JWT \u8ba4\u8bc1<\/li>\n<li>\u652f\u6301 Swagger \u6587\u6863(\u57fa\u4e8eswaggo)<\/li>\n<li>\u4f7f\u7528 make \u6765\u7ba1\u7406 Go \u5de5\u7a0b<\/li>\n<li>\u4f7f\u7528 shell(admin.sh) \u811a\u672c\u6765\u7ba1\u7406\u8fdb\u7a0b<\/li>\n<li>\u652f\u6301\u591a\u73af\u5883\u914d\u7f6e<\/li>\n<\/ul>\n<h2>\u76ee\u5f55\u7ed3\u6784<\/h2>\n<pre><code>\u251c\u2500\u2500 Makefile                     # \u9879\u76ee\u7ba1\u7406\u6587\u4ef6 \u251c\u2500\u2500 conf                         # \u914d\u7f6e\u6587\u4ef6\u7edf\u4e00\u5b58\u653e\u76ee\u5f55 \u251c\u2500\u2500 config                       # \u4e13\u95e8\u7528\u6765\u5904\u7406\u914d\u7f6e\u548c\u914d\u7f6e\u6587\u4ef6\u7684 Go package                  \u251c\u2500\u2500 db.sql                       # \u5728\u90e8\u7f72\u65b0\u73af\u5883\u65f6\uff0c\u53ef\u4ee5\u767b\u5f55 MySQL \u5ba2\u6237\u7aef\uff0c\u6267\u884c source db.sql \u521b\u5efa\u6570\u636e\u5e93\u548c\u8868 \u251c\u2500\u2500 docs                         # swagger \u6587\u6863\uff0c\u6267\u884c swag init \u751f\u6210\u7684 \u251c\u2500\u2500 handler                      # \u7c7b\u4f3c MVC \u67b6\u6784\u4e2d\u7684 C\uff0c\u7528\u6765\u8bfb\u53d6\u8f93\u5165\uff0c\u5e76\u5c06\u5904\u7406\u6d41\u7a0b\u8f6c\u53d1\u7ed9\u5b9e\u9645\u7684\u5904\u7406\u51fd\u6570\uff0c\u6700\u540e\u8fd4\u56de\u7ed3\u679c \u251c\u2500\u2500 log                          # \u5b58\u653e\u65e5\u5fd7\u7684\u76ee\u5f55 \u251c\u2500\u2500 main.go                      # \u9879\u76ee\u5165\u53e3\u6587\u4ef6 \u251c\u2500\u2500 model                        # \u6570\u636e\u5e93 model \u251c\u2500\u2500 pkg                          # \u4e00\u4e9b\u5c01\u88c5\u597d\u7684 package \u251c\u2500\u2500 repository                   # \u6570\u636e\u8bbf\u95ee\u5c42 \u251c\u2500\u2500 router                       # \u8def\u7531\u53ca\u4e2d\u95f4\u4ef6\u76ee\u5f55 \u251c\u2500\u2500 service                      # \u4e1a\u52a1\u903b\u8f91\u5c01\u88c5 \u251c\u2500\u2500 schedule                     # \u4efb\u52a1\u8c03\u5ea6\u914d\u7f6e\u76ee\u5f55 \u2514\u2500\u2500 scripts                      # \u5b58\u653e\u7528\u4e8e\u6267\u884c\u5404\u79cd\u6784\u5efa\uff0c\u5b89\u88c5\uff0c\u5206\u6790\u7b49\u64cd\u4f5c\u7684\u811a\u672c <\/code><\/pre>\n<h2>\u4e0b\u8f7d\u5b89\u88c5<\/h2>\n<pre><code># \u8fdb\u5165\u5230\u81ea\u5df1\u7684\u5f00\u53d1\u76ee\u5f55\uff0c\u4e0b\u8f7d\u5b89\u88c5\u5373\u53ef\uff0c\u53ef\u4ee5\u4e0d\u7528\u662f GOPATH git clone https:\/\/github.com\/1024casts\/snake <\/code><\/pre>\n<h2>\u5feb\u901f\u5f00\u59cb<\/h2>\n<p>TIPS: \u9700\u8981\u672c\u5730\u5b89\u88c5\u6570\u636e\u5e93\u548c redis<\/p>\n<pre><code>\/\/ \u8fdb\u5165\u5230\u4e0b\u8f7d\u76ee\u5f55 cd snake  \/\/ \u751f\u6210\u672c\u5730\u73af\u5883\u914d\u7f6e\u6587\u4ef6 cp config.sample.yaml config.local.yaml  \/\/ \u7f16\u8bd1 make build  \/\/ \u8fd0\u884c .\/scripts\/admin.sh start <\/code><\/pre>\n<h2>\u5e38\u7528\u547d\u4ee4<\/h2>\n<ul>\n<li>make help \u67e5\u770b\u5e2e\u52a9<\/li>\n<li>make dep \u4e0b\u8f7d go \u4f9d\u8d56\u5305<\/li>\n<li>make build \u7f16\u8bd1\u9879\u76ee<\/li>\n<li>make swag-init \u751f\u6210\u63a5\u53e3\u6587\u6863(\u9700\u8981\u91cd\u65b0\u7f16\u8bd1)<\/li>\n<li>make test-coverage \u751f\u6210\u6d4b\u8bd5\u8986\u76d6<\/li>\n<li>make lint \u68c0\u67e5\u4ee3\u7801\u89c4\u8303<\/li>\n<\/ul>\n<h2>\u6a21\u5757<\/h2>\n<ul>\n<li>\u7528\u6237(\u793a\u4f8b)<\/li>\n<\/ul>\n<h2>\u63a5\u53e3\u6587\u6863<\/h2>\n<p><code>http:\/\/localhost:8080\/swagger\/index.html<\/code><\/p>\n<h2>\u5f00\u53d1\u89c4\u7ea6<\/h2>\n<ul>\n<li>\u914d\u7f6e\u8bf4\u660e<\/li>\n<li>\u9519\u8bef\u7801\u8bbe\u8ba1<\/li>\n<li>service \u7684\u4f7f\u7528\u89c4\u5219<\/li>\n<li>repository \u7684\u4f7f\u7528\u89c4\u5219<\/li>\n<li>cache \u4f7f\u7528\u8bf4\u660e<\/li>\n<\/ul>\n<h2>CHANGELOG<\/h2>\n<ul>\n<li>\u66f4\u65b0\u65e5\u5fd7<\/li>\n<\/ul>\n<h2>\u8c01\u5728\u7528<\/h2>\n<ul>\n<li>1024 \u8bfe\u5802<\/li>\n<\/ul>\n<h2>Discussion<\/h2>\n<ul>\n<li>Issue: https:\/\/github.com\/1024casts\/snake\/issues<\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5927\u5bb6\u4e00\u8d77\u8ba8\u8bba\u3001\u4ea4\u6d41\uff0c\u65b9\u4fbf\u7684\u8bdd\u53ef\u4ee5\u7ed9\u4e2a star \u3002 https:\/\/github.com\/1024casts\/snake<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1478657\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vtwoextb <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5b66\u4e60\u5b66\u4e60                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u4eab\u4e00\u6b3e\u9002\u5408\u4e8e\u5feb\u901f\u5f00\u53d1\u4e1a\u52a1\u7684 Go&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/86805"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86805"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/86805\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86805"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}