{"id":1727,"date":"2020-10-08T01:55:42","date_gmt":"2020-10-07T17:55:42","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=1727"},"modified":"2022-02-16T21:52:24","modified_gmt":"2022-02-16T13:52:24","slug":"iris-query-string-2021ironman","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2020\/10\/08\/iris-query-string-2021ironman\/","title":{"rendered":"Iris \u9019\u500b\u5728 go \u8a9e\u8a00\u4e0a\u5730\u8868\u6700\u5feb\u7684\u7db2\u9801\u6846\u67b6-iris\u7684 query string"},"content":{"rendered":"<h1>query string<\/h1>\n<p>\u5728\u4ecb\u7d39\u5b8c\u50b3\u905e\u4f7f\u7528\u8005\u8cc7\u6599\u624b\u6bb5\u4e4b\u5f8c\u8981\u958b\u59cb\u4ecb\u7d39\u4f7f\u7528\u8005\u50b3\u905e\u8cc7\u8a0a\u5230\u7db2\u9801\u4f3a\u670d\u5668\u7684\u65b9\u6cd5\uff0c\u5728http\u5354\u5b9a\u4e2d\u6709\u5169\u7a2e\u63a5\u6536\u7684\u65b9\u5f0f\uff0c\u6240\u4ee5\u9019\u7bc7\u5148\u4ecb\u7d39\u5176\u4e00query string\u3002<\/p>\n<p><!--more--><\/p>\n<h2>query string<\/h2>\n<p>query string \u662f\u4f7f\u7528\u8005\u50b3\u905e\u8acb\u6c42\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u4e5f\u662f\u6700\u57fa\u790e\u7684\u8acb\u6c42\u65b9\u6cd5\uff0c\u96d6\u7136\u57fa\u790e\u4f46\u662f\u4e5f\u662f\u6700\u7c21\u55ae\u5bb9\u6613\u4f7f\u7528\uff0c\u6240\u4ee5\u9019\u908a\u5148\u4ecb\u7d39\u9019\u500b\u6613\u61c2\u4e14\u7c21\u55ae\u4f7f\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<h3>query string \u662f\u4ec0\u9ebc<\/h3>\n<p>\u6240\u8b02\u7684query string\u5c31\u662f\u8acb\u6c42url\u4e4b\u4e2d<code>?<\/code>\u5f8c\u9762\u7684\u53c3\u6578\uff0c\u4f8b\u5982\u4e0b\u9762\u4f8b\u5b50\u4e2d\u7684lastname\u548cfirstname <\/p>\n<pre><code class=\"language-bash\">https:\/\/www.develop-note.com\/api\/custom?lastname=chang&amp;firstname=kirai<\/code><\/pre>\n<p>\u5728\u4ecb\u7d39\u5b8c\u4ec0\u9ebc\u662fquery string\u4e4b\u5f8c\u8981\u958b\u59cb\u4ecb\u7d39\u5728iris\u4e2d\u5982\u4f55\u53d6\u5f97query string\u3002<\/p>\n<h3>iris query string \u8655\u7406\u7684\u65b9\u6cd5<\/h3>\n<p>\u5728iris\u4e2d\u6709\u5e7e\u500b\u8655\u7406query string\u7684\u65b9\u6cd5\uff0c\u4e4b\u524d\u6709\u4ecb\u7d39\u4e00\u500b\uff0c\u63a5\u4e0b\u4f86\u518d\u591a\u4ecb\u7d39\u5e7e\u500b\uff0c\u8acb\u770b\u4e0b\u5217\u5167\u5bb9<\/p>\n<ul>\n<li>URLParamExists(name string) bool<\/li>\n<li>URLParamDefault(name string, def string) string<\/li>\n<li>URLParam(name string) string<\/li>\n<li>URLParamTrim(name string) string<\/li>\n<li>URLParamInt(name string) (int, error)<\/li>\n<li>URLParamIntDefault(name string, def int) int<\/li>\n<li>URLParams() map[string]string<\/li>\n<\/ul>\n<p>\u9019\u908a\u7a0d\u4f5c\u89e3\u91cb\uff0c\u7c21\u55ae\u8aaa\u5c31\u662f\u5f8c\u7db4\u8a5e\u6709<code>Default<\/code>\u5c31\u662f\u5982\u679c\u6c92\u6709\u8a72\u53c3\u6578\u5c31\u6703\u8fd4\u9084<code>def<\/code>\u9019\u500b\u503c\uff0c\u9084\u6709URLParamInt\u5c31\u662f\u5c07\u6539\u540d\u7a31\u7684query string\u8f49\u63db\u6210<code>int<\/code>\u6240\u4ee5\u5f8c\u7db4\u6709\u57fa\u790e\u985e\u5225\u540d\u7a31\u7684\u65b9\u6cd5\u5c31\u662f\u8f49\u63db\u6210\u8a72\u57fa\u790e\u985e\u5225\uff0c\u9084\u6709URLParamTrim\u662f\u5c07\u5176\u503c\u88e1\u9762\u982d\u5c3e\u7684\u7a7a\u767d\u90fd\u53bb\u9664\u6389\u7684\u503c\uff0c\u6700\u5f8cURLParams\u5c31\u662f\u53d6\u5f97\u6240\u4ee5query string\u8f49\u63db\u6210map\u7684\u7d50\u679c\u3002<br \/>\n\u7d50\u679c\u8b1b\u4e86\u90a3\u9ebc\u591a\u9019\u500bquery string\u5230\u5e95\u8a72\u600e\u9ebc\u4f7f\u7528\u5462\uff0c\u8acb\u5927\u5bb6\u770b\u770b\u4e0b\u5217\u4f8b\u5b50<\/p>\n<pre><code class=\"language-go\"> app.Get(&quot;\/api\/custom&quot;, func(ctx iris.Context) {\n        firstname := ctx.URLParamDefault(&quot;firstname&quot;, &quot;Guest&quot;)\n        lastname := ctx.URLParam(&quot;lastname&quot;)\n\n        ctx.Writef(&quot;Hello %s %s&quot;, firstname, lastname)\n    })<\/code><\/pre>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u4ecb\u7d39\u5b8cquery string\u4e4b\u5f8c\u8b93\u8b80\u8005\u5c0d\u65bc\u8655\u7406\u4f7f\u7528\u8005\u7684\u8acb\u6c42\u6709\u4e00\u500b\u57fa\u672c\u7684\u6982\u5ff5\uff0c\u4e0d\u904equery string\u6709\u9577\u5ea6\u9650\u5236\uff0c\u800c\u4e14\u6709\u88ab\u7aba\u770b\u5230\u7684\u98a8\u96aa\uff0c\u6240\u4ee5\u4e0b\u4e00\u7bc7\u4ecb\u7d39form post\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>query string \u5728\u4ecb\u7d39\u5b8c\u50b3\u905e\u4f7f\u7528\u8005\u8cc7\u6599\u624b\u6bb5\u4e4b\u5f8c\u8981\u958b\u59cb\u4ecb\u7d39\u4f7f\u7528\u8005\u50b3\u905e\u8cc7\u8a0a\u5230\u7db2\u9801\u4f3a\u670d\u5668\u7684\u65b9\u6cd5\uff0c\u5728http &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2020\/10\/08\/iris-query-string-2021ironman\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Iris \u9019\u500b\u5728 go \u8a9e\u8a00\u4e0a\u5730\u8868\u6700\u5feb\u7684\u7db2\u9801\u6846\u67b6-iris\u7684 query string\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[158,81,84],"class_list":["post-1727","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2020ironman","tag-go","tag-iris"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=1727"}],"version-history":[{"count":16,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1727\/revisions"}],"predecessor-version":[{"id":2956,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1727\/revisions\/2956"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=1727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=1727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=1727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}