{"id":9515,"date":"2022-08-04T15:50:13","date_gmt":"2022-08-04T07:50:13","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=9515"},"modified":"2022-08-04T16:01:55","modified_gmt":"2022-08-04T08:01:55","slug":"go-swagger","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/08\/04\/go-swagger\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528go-swagger\u6587\u6863"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">1\u3001\u5b89\u88c5\u6240\u9700\u8981\u7684\u5305\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go get -u github.com\/swaggo\/swag\/cmd\/swag\ngo get -u github.com\/swaggo\/gin-swagger\ngo get -u github.com\/swaggo\/files<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u547d\u4ee4swag -v\u67e5\u770b\u662f\u5426\u5b89\u88c5\u6210\u529f\uff0c\u5982\u679c\u6ca1\u6709\u6210\u529f\uff0c\u9700\u8981\u8fdb\u5165\u8def\u5f84$GOPATH\/github.com\/swaggo\/swag@v1.8.4\/cmd\/swag\u4e0b\uff0c\u6267\u884c\u547d\u4ee4go install\uff0c\u7136\u540e\u4eceGOBIN\u8def\u5f84\u4e0b\u5c06swag\u590d\u5236\u4e00\u4efd\u5230$GOPATH\/bin\u8def\u5f84\u4e0b\u5373\u53ef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5728main.go\u4e2d\u6dfb\u52a0\u5982\u4e0b\u6ce8\u91ca\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ @title Go-site Example API\r\n\/\/ @version 1.0\r\n\/\/ @description This is a sample server Petstore server.\r\n\/\/ @termsOfService http:\/\/swagger.io\/terms\/\r\n\/\/ @contact.name API Support\r\n\/\/ @contact.url http:\/\/www.swagger.io\/support\r\n\/\/ @contact.email support@swagger.io\r\n\/\/ @license.name Apache 2.0\r\n\/\/ @license.url http:\/\/www.apache.org\/licenses\/LICENSE-2.0.html\r\n\/\/ @host 127.0.0.1:8889          #\u8868\u793a\u5b9e\u9645\u8fd0\u884c\u7684\u4e3b\u673a\u548c\u7aef\u53e3\r\n\/\/ @BasePath\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"265\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/7.png\" alt=\"\" class=\"wp-image-9519\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/7.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/7-300x112.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/7-600x224.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5728router\u4e2d\u6dfb\u52a0swagger\u7684handler\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6d4f\u89c8\u5668\u8f93\u5165\u53ef\u4ee5\u6253\u5f00\u9875\u9762\r\n\/\/ http:\/\/localhost:8900\/swagger\/index.html\r\nrouter.GET(\"\/swagger\/*any\", ginSwagger.WrapHandler(swaggerFiles.Handler))\r<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"157\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/9.png\" alt=\"\" class=\"wp-image-9525\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/9.png 745w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/9-300x63.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/9-600x126.png 600w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u65f6\u5bfc\u5165\u5982\u4e0b\u5305\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"182\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/10.png\" alt=\"\" class=\"wp-image-9527\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/10.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/10-300x77.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/10-600x154.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7b2c\u4e00\u4e2adocs\u4e3aswag init\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u81ea\u52a8\u521b\u5efa\u7684<\/li><li>\u5176\u4f59\u4e24\u4e2a\u5305\u53ef\u4ee5\u624b\u52a8\u5bfc\u5165\uff0c\u4e5f\u53ef\u4ee5\u6267\u884cgo fmt\u540e\u4f1a\u81ea\u52a8\u52a0\u8f7d\u8fdb\u6765(\u524d\u63d0\u662fvim\u914d\u7f6e\u4e86go\u5f00\u53d1\u73af\u5883)<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728\u4e1a\u52a1\u903b\u8f91\u4ee3\u7801\u4e2d\uff0c\u6dfb\u52a0\u6ce8\u91ca\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"208\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/11.png\" alt=\"\" class=\"wp-image-9530\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/11.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/11-300x88.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/11-600x176.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u6b64\u6ce8\u91ca\u4e0d\u662f\u4e71\u5199\u7684\uff0c\u8981\u6839\u636e\u5b98\u65b9\u8981\u6c42\u586b\u5199<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u5728\u9879\u76ee\u8ddf\u76ee\u5f55\u4e0b\uff0c\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u751f\u6210docs\u6587\u4ef6\u5939\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>swag init<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"258\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/12.png\" alt=\"\" class=\"wp-image-9532\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/12.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/12-300x109.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/12-600x218.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u901a\u8fc7\u94fe\u63a5\u8bbf\u95ee\uff1ahttp:\/\/10.9.2.247:8900\/swagger\/index.html#\/<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"631\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/13.png\" alt=\"\" class=\"wp-image-9534\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/13.png 724w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/13-300x261.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/08\/13-600x523.png 600w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u6ce8\u91ca\u7528\u6cd5\u53ef\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;github.com\/swaggo\/swag\/blob\/master\/README_zh-CN.md<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u5b89\u88c5\u6240\u9700\u8981\u7684\u5305\uff1a \u6267\u884c\u547d\u4ee4swag -v\u67e5\u770b\u662f\u5426\u5b89\u88c5\u6210\u529f\uff0c\u5982\u679c\u6ca1\u6709\u6210\u529f\uff0c\u9700\u8981\u8fdb\u5165\u8def\u5f84$GOPATH\/git [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":9521,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-9515","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/9515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=9515"}],"version-history":[{"count":14,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/9515\/revisions"}],"predecessor-version":[{"id":9536,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/9515\/revisions\/9536"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/9521"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=9515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=9515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=9515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}