Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DecodeURIComponent func(s string) (string, error) = url.QueryUnescape
DecodeURIComponent 解码
e.g. ("") => "", nil
View Source
var EncodeURIComponent func(s string) string = url.QueryEscape
EncodeURIComponent 编码
e.g. ("") => ""
Parse 解析url(http、https、rtsp、rtmp等协议)
PS: (1) url.Parse VS url.ParseRequestURI: 当要解析的url字符串中包含有字符“#”时,使用url.Parse解析,会导致#后面的参数解析不出来。而使用ParseRequestURI就能解析到.
使用场景: (a) 不关心#后面的数据,使用: url.Parse (b) 关心#后面的数据,使用: url.ParseRequestURI
GoLand教程-Go URL解析
https://mp.weixin.qq.com/s/i6uEUzvu5BPna5QtSYDSMQ
golang url.Parse 解析
https://blog.csdn.net/zhuyuqiang1238/article/details/121807708
@param rawURL !!!不能是如下格式: "localhost:8080"
e.g.
u, err := urlKit.Parse("http://localhost:8080/go?a=123&b=456") if err != nil { panic(err) } fmt.Println(u.Scheme) // http fmt.Println(u.Host) // localhost:8080 fmt.Println(u.Hostname()) // localhost fmt.Println(u.Port()) // 8080 fmt.Println(u.Path) // /go fmt.Println(u.RawQuery) // a=123&b=456 fmt.Println(u.Query()) // map[a:[123] b:[456]]
View Source
var ParseQuery func(query string) (url.Values, error) = url.ParseQuery
ParseQuery
e.g.
u, err := urlKit.Parse("http://localhost:8080/go?a=123&b=456") if err != nil { panic(err) } fmt.Println(u.RawQuery) // a=123&b=456 m, err := urlKit.ParseQuery(u.RawQuery) if err != nil { panic(err) } fmt.Println(m) // map[a:[123] b:[456]]
View Source
var ParseRequestURI func(rawURL string) (*url.URL, error) = url.ParseRequestURI
Functions ¶
func AttachQueryParamsToUrl ¶
AttachQueryParamsToUrl
@param url (1) 原则上,不能为"",应该以"http://"或"https://"开头
(2) 不能是Request.URL.RawQuery
func ToBodyString ¶
func ToQueryString ¶
ToQueryString
@param m 会对值进行 编码 操作 @return 可能为""
e.g.
(nil) => ""
e.g.1
m := map[string]string{ "a": "test", "b": "测试", } fmt.Println(urlKit.ToQueryString(m)) // a=test&b=%E6%B5%8B%E8%AF%95
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.