{"id":15442,"date":"2024-11-17T21:10:59","date_gmt":"2024-11-17T13:10:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15442"},"modified":"2024-11-17T21:10:59","modified_gmt":"2024-11-17T13:10:59","slug":"go%e4%b8%ad%e7%9a%84net-url%e5%8c%85%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15442\/","title":{"rendered":"Go\u4e2d\u7684net\/url\u5305\u5b66\u4e60\u7b14\u8bb0"},"content":{"rendered":"<p>GO\u4e2d\u7684net\/url\u5305\uff0c\u5b9e\u73b0\u5bf9URL\u7684\u5904\u7406\u3002<\/p>\n<h3><strong>1\u3001\u5bf9URL\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801<\/strong><\/h3>\n<p><strong>func QueryEscape(s string) string<\/strong><br \/>\nQueryEscape\u51fd\u6570\u5bf9s\u8fdb\u884c\u8f6c\u7801\u4f7f\u4e4b\u53ef\u4ee5\u5b89\u5168\u7684\u7528\u5728URL\u67e5\u8be2\u91cc\u3002<\/p>\n<p><strong>func QueryUnescape(s string) (string, error)<\/strong><br \/>\nQueryUnescape\u51fd\u6570\u7528\u4e8e\u5c06QueryEscape\u8f6c\u7801\u7684\u5b57\u7b26\u4e32\u8fd8\u539f\u3002\u5b83\u4f1a\u628a%AB\u6539\u4e3a\u5b57\u82820xAB\uff0c\u5c06\u2019+\u2019\u6539\u4e3a\u2019 \u2018\u3002\u5982\u679c\u6709\u67d0\u4e2a%\u540e\u9762\u672a\u8ddf\u4e24\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff0c\u672c\u51fd\u6570\u4f1a\u8fd4\u56de\u9519\u8bef\u3002<\/p>\n<p>&nbsp;<\/p>\n<h3>2\u3001\u5bf9Path(\u8def\u5f84)\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801<\/h3>\n<p><strong>func PathEscape(s string) string<\/strong><\/p>\n<p><strong>func PathUnescape(s string) (string, error)<\/strong><\/p>\n<p><strong>tips 01 : PathEscape\u53ea\u5bf9 \/ \u8fdb\u884c\u7f16\u7801\uff0c\u6ce8\u610f\u548cQueryEscape\u7684\u533a\u522b;<\/strong><\/p>\n<h3>\u00a03\u3001URL\u7c7b\u578b\u00a0\uff0a\u91cd\u70b9<\/h3>\n<pre>type URL struct {\r\n\u00a0\u00a0\u00a0 Scheme\u00a0\u00a0 string\r\n\u00a0\u00a0\u00a0 Opaque\u00a0\u00a0 string\u00a0\u00a0\u00a0 \/\/ \u7f16\u7801\u540e\u7684\u4e0d\u900f\u660e\u6570\u636e\r\n\u00a0\u00a0\u00a0 User\u00a0\u00a0\u00a0\u00a0 *Userinfo \/\/ \u7528\u6237\u540d\u548c\u5bc6\u7801\u4fe1\u606f\r\n\u00a0\u00a0\u00a0 Host\u00a0\u00a0\u00a0\u00a0 string\u00a0\u00a0\u00a0 \/\/ host\u6216host:port\r\n\u00a0\u00a0\u00a0 Path\u00a0\u00a0\u00a0\u00a0 string\r\n\u00a0\u00a0\u00a0 RawQuery string \/\/ \u7f16\u7801\u540e\u7684\u67e5\u8be2\u5b57\u7b26\u4e32\uff0c\u6ca1\u6709'?'\r\n\u00a0\u00a0\u00a0 Fragment string \/\/ \u5f15\u7528\u7684\u7247\u6bb5\uff08\u6587\u6863\u4f4d\u7f6e\uff09\uff0c\u6ca1\u6709'#'\r\n}<\/pre>\n<p>\u76f8\u5173\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>func Parse(rawurl string) (url *URL, err error)\r\nfunc ParseRequestURI(rawurl string) (url *URL, err error)\r\nfunc (u *URL) IsAbs() bool\r\nfunc (u *URL) Query() Values\r\nfunc (u *URL) RequestURI() string\r\nfunc (u *URL) String() string\r\nfunc (u *URL) Parse(ref string) (*URL, error)\r\nfunc (u *URL) ResolveReference(ref *URL) *URL<\/pre>\n<h3>4\u3001URL\u4e2d\u7684key=value\u952e\u503c\u5bf9<\/h3>\n<pre>type Values map[string][]string<\/pre>\n<p>\u76f8\u5173\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>func ParseQuery(query string) (m Values, err error)\r\nfunc (v Values) Get(key string) string\r\nfunc (v Values) Set(key, value string)\r\nfunc (v Values) Add(key, value string)\r\nfunc (v Values) Del(key string)\r\nfunc (v Values) Encode() string<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GO\u4e2d\u7684net\/url\u5305\uff0c\u5b9e\u73b0\u5bf9URL\u7684\u5904\u7406\u3002 1\u3001\u5bf9URL\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801 func QueryEscape(s string) string QueryEscape\u51fd\u6570\u5bf9s\u8fdb\u884c\u8f6c\u7801\u4f7f\u4e4b\u53ef\u4ee5\u5b89\u5168\u7684\u7528\u5728URL\u67e5\u8be2\u91cc\u3002 func QueryUnescape(s string) (string, error) QueryUnescape\u51fd\u6570\u7528\u4e8e\u5c06QueryEscape\u8f6c\u7801\u7684\u5b57\u7b26\u4e32\u8fd8\u539f\u3002\u5b83\u4f1a\u628a%AB\u6539\u4e3a\u5b57\u82820xAB\uff0c\u5c06\u2019+\u2019\u6539\u4e3a\u2019 \u2018\u3002\u5982\u679c\u6709\u67d0\u4e2a%\u540e\u9762\u672a\u8ddf\u4e24\u4e2a\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff0c\u672c\u51fd\u6570\u4f1a\u8fd4\u56de\u9519\u8bef\u3002 &nbsp; 2\u3001\u5bf9Path(\u8def\u5f84)\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801 func PathEscape(s string) string func PathUnescape(s string) (string, error) tips 01 : PathEscape\u53ea\u5bf9 \/ \u8fdb\u884c\u7f16\u7801\uff0c\u6ce8\u610f\u548cQueryEscape\u7684\u533a\u522b; \u00a03\u3001URL\u7c7b\u578b\u00a0\uff0a\u91cd\u70b9 type URL struct { \u00a0\u00a0\u00a0 Scheme\u00a0\u00a0 string \u00a0\u00a0\u00a0 Opaque\u00a0\u00a0 string\u00a0\u00a0\u00a0 \/\/ \u7f16\u7801\u540e\u7684\u4e0d\u900f\u660e\u6570\u636e \u00a0\u00a0\u00a0 User\u00a0\u00a0\u00a0\u00a0 *Userinfo \/\/ \u7528\u6237\u540d\u548c\u5bc6\u7801\u4fe1\u606f \u00a0\u00a0\u00a0 Host\u00a0\u00a0\u00a0\u00a0 string\u00a0\u00a0\u00a0 \/\/ host\u6216host:port \u00a0\u00a0\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15442","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15442","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15442"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15442\/revisions"}],"predecessor-version":[{"id":15443,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15442\/revisions\/15443"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}