{"id":10647,"date":"2022-11-14T09:19:21","date_gmt":"2022-11-14T01:19:21","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=10647"},"modified":"2022-11-14T12:05:14","modified_gmt":"2022-11-14T04:05:14","slug":"search","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2022\/11\/14\/search\/","title":{"rendered":"go\u8bed\u8a00\u4e4b\u641c\u7d22\u529f\u80fd\u5b9e\u73b0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728\u6587\u7ae0<a href=\"https:\/\/blog.ywdevops.cn\/index.php\/2022\/11\/11\/page\/\">go\u8bed\u8a00\u4e4b\u5206\u9875\u529f\u80fd<\/a>\u4e2d\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u5982\u679c\u8981\u5b9e\u73b0\u5206\u9875\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u5c06\u9875\u7684\u6570\u91cf\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u5230\u540e\u53f0\uff0c\u7136\u540e\u6839\u636e\u9875\u6570\u548c\u6bcf\u9875\u7684\u6570\u636e\u91cf\u6765\u8fdb\u884c\u67e5\u627e\u4ece\u800c\u5b9e\u73b0\u5206\u9875\u529f\u80fd(PageNum * PageSize)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u641c\u7d22\u529f\u80fd\u7684\u5b9e\u73b0\u539f\u7406\u76f8\u540c\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5c06\u8981\u641c\u7d22\u7684\u5b57\u6bb5\u4f20\u9012\u5230\u540e\u53f0\uff0c\u540c\u65f6\u4f20\u9012\u9875\u6570\u8fc7\u53bb\uff0c\u7136\u540e\u6839\u636e\u5b57\u6bb5\u540d\u4ee5\u53ca\u9875\u6570\u548c\u6bcf\u9875\u6570\u636e\u91cf\u4e00\u8d77\u6765\u5b9e\u73b0\u641c\u7d22\u529f\u80fd<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u4f8b\u5b50\u8fd8\u662f\u4ee5\u8fd0\u7ef4\u5e73\u53f0oamp\u4e2d\u95f4\u4ef6\u6a21\u5757\u4e3a\u4f8b\u5b50\uff0c\u5b9e\u73b0\u641c\u7d22<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u5728\u6587\u4ef6\/oamp\/router\/api\/v1\/middleware.go\u4e2d\u83b7\u53d6\u4e2d\u95f4\u4ef6\u7684\u7ed3\u6784\u4f53\u4e2d\u6dfb\u52a0\u641c\u7d22\u5b57\u6bb5SearchMiddle\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"717\" height=\"132\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/2-9.png\" alt=\"\" class=\"wp-image-10653\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/2-9.png 717w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/2-9-300x55.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/2-9-600x110.png 600w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5b9e\u4f8b\u5316\u4e2d\u95f4\u4ef6\u670d\u52a1\u7ed3\u6784\u4f53\uff0c\u5e76\u7ed9\u5b57\u6bb5\u8d4b\u503c\uff0c\u8c03\u7528\u65b9\u6cd5\u83b7\u53d6\u4e2d\u95f4\u4ef6\u6570\u636e\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"245\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/4-7.png\" alt=\"\" class=\"wp-image-10660\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/4-7.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/4-7-300x104.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/4-7-600x207.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u5728\u65b9\u6cd5GetMiddleware()\u4e2d\u8c03\u7528\u51fd\u6570MiddlePage\u5e76\u4f20\u9012\u662f\u4e09\u4e2a\u53c2\u6570\u83b7\u53d6\u6570\u636e\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>middlepage, err := models.MiddlePage(g.PageNum, setting.AppSetting.PageSize, g.SearchMiddle)\n#SearchMiddle\u8868\u793a\u8981\u641c\u7d22\u7684\u5b57\u6bb5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5728\u51fd\u6570MiddlePage\u4e2d\uff0c\u67e5\u8be2\u6570\u636e\u5e93\u83b7\u53d6\u6570\u636e\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>err := db.Where(\"id &gt; ?\", PageNum*PageSize).Where(\"ip_address = @searchmiddle OR middleware_name = @searchmiddle\", sql.Named(\"searchmiddle\", SearchMiddle)).Limit(PageSize).Find(&amp;middle).Error<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u4ee3\u7801\u4e2d\u901a\u8fc7\u4e24\u4e2aWhere\u6765\u5224\u65ad\u6761\u4ef6\uff0c\u7b2c\u4e00\u4e2a\u4e3a\u83b7\u53d6\u6570\u636e\u7684id\u4fe1\u606f\uff0c\u6839\u636ePageNum\u548cPageSize\uff0c\u7b2c\u4e8c\u4e2aWhere\u4e3a\u7b5b\u9009\u6761\u4ef6\uff0c\u5f53ip_address\u6216\u8005middleware_name\u7b49\u4e8e\u641c\u7d22\u7684\u5b57\u6bb5\u4e3a\u6761\u4ef6\uff0c@serchmiddle\u4e3a\u53d8\u91cf\uff0csql.Named\u4e2d\u6307\u5b9a\u53d8\u91cf\u5e76\u8bbe\u7f6e\u503c\uff0c\u8fd9\u4e2a\u503c\u5c31\u662f\u4f20\u9012\u8fc7\u6765\u7684\u6570\u636e\uff0csql.Named\u4e3a\u56fa\u5b9a\u5199\u6cd5\uff0c\u4f8b\u5982\uff1a\u6211\u4eec\u8f93\u5165\u8981\u641c\u7d22\u7684\u4e2d\u95f4\u4ef6\u540d\u4e3anginx \uff0c\u9875\u6570PageNum\u4e3a\u7b2c\u4e00\u9875\uff0c\u90a3\u4e48\u5728\u67e5\u8be2\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0c\u5c31\u662f\u67e5\u627e\u5f53middleware_name\u4e3aNginx\u7684\u6570\u636e\uff0c\u67e5\u627e\u540e\u4eceid\u4e3a0\u5f00\u59cb\u83b7\u53d610\u6761\u6570\u636e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u4ed6\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u914d\u7f6e\u524d\u53f0\u5b9e\u73b0\u641c\u7d22+\u5206\u9875\uff0c\u540e\u53f0\u5728\u8fd4\u56de\u6570\u636e\u7684\u65f6\u5019\uff0c\u8981\u987a\u4fbf\u8fd4\u56de\u4e00\u4e0b\u641c\u7d22\u7684\u5b57\u6bb5\u540d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"161\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-6.png\" alt=\"\" class=\"wp-image-10664\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-6.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-6-300x68.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/5-6-600x136.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"226\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-5.png\" alt=\"\" class=\"wp-image-10665\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-5.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-5-300x96.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/11\/6-5-600x191.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u8981\u8fd4\u56de\u641c\u7d22\u7684\u5b57\u6bb5\u540d\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a\u524d\u53f0vue\u5728\u8c03\u7528\u540e\u53f0\u63a5\u53e3\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u8f93\u5165\u8981\u641c\u7d22\u7684\u5b57\u6bb5\uff0c\u90a3\u4e48\u9ed8\u8ba4\u4f1a\u5c06\u5b57\u6bb5\u4e0e\u7b2c\u4e00\u9875\u7684\u9875\u7801\u4f20\u9012\u5230\u540e\u53f0\uff0c\u5982\u679c\u641c\u7d22\u7684\u6570\u636e\u8d85\u8fc7\u4e8610\u6761\uff0c\u5f53\u70b9\u51fb\u7b2c2\u9875\u7684\u65f6\u5019\uff0c\u6b64\u65f6\u6ca1\u6709\u5c06\u641c\u7d22\u5b57\u6bb5\u4f20\u9012\u7ed9\u540e\u53f0\uff0c\u53ea\u4f20\u9012\u4e86\u9875\u7801\u6570\uff0c\u90a3\u4e48\u6b64\u65f6\u83b7\u53d6\u7684\u6570\u636e\uff0c\u5c31\u662f\u6309\u7167\u5168\u90e8\u6570\u636e\u83b7\u53d6\u7684\uff0c\u76f8\u5f53\u4e8e\u83b7\u53d6\u7684\u5168\u90e8\u6570\u636e\u7684\u7b2c2\u9875\uff0c\u56e0\u6b64\u70b9\u51fb\u7b2c2\u9875\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5e94\u8be5\u540c\u6837\u5c06\u641c\u7d22\u5b57\u6bb5\u548c\u9875\u7801\u4f20\u9012\u5230\u540e\u53f0\uff0c\u5177\u4f53vue\u4e2d\u5982\u4f55\u5b9e\u73b0\uff0c\u53ef\u67e5\u770b\u6587\u7ae0<a href=\"https:\/\/blog.ywdevops.cn\/index.php\/2022\/09\/20\/vue-5\/\" target=\"_blank\" rel=\"noreferrer noopener\">vue\u8868\u683c\u5b9e\u73b0\u641c\u7d22\u529f\u80fd<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6587\u7ae0go\u8bed\u8a00\u4e4b\u5206\u9875\u529f\u80fd\u4e2d\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u5982\u679c\u8981\u5b9e\u73b0\u5206\u9875\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u5c06\u9875\u7684\u6570\u91cf\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u5230\u540e\u53f0\uff0c\u7136\u540e\u6839\u636e\u9875\u6570\u548c\u6bcf [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":10649,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-10647","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\/10647","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=10647"}],"version-history":[{"count":10,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10647\/revisions"}],"predecessor-version":[{"id":10669,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/10647\/revisions\/10669"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/10649"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=10647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=10647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=10647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}