diff --git a/http.go b/http.go index 0991fb3..30ff6bf 100644 --- a/http.go +++ b/http.go @@ -14,7 +14,7 @@ import ( "time" ) -const Version = "1.0.6" +const Version = "1.0.7" // Response 返回内容 type Response struct { diff --git a/url.go b/url.go new file mode 100644 index 0000000..904f880 --- /dev/null +++ b/url.go @@ -0,0 +1,29 @@ +package gorequest + +import ( + "net/url" +) + +type ResponseUrlParse struct { + Scheme string `json:"scheme"` // 协议 + Hostname string `json:"hostname"` // 主机名 + Port string `json:"port"` // 端口 + Path string `json:"path"` // 路径 + RawQuery string `json:"raw_query"` // 参数 ? + Fragment string `json:"fragment"` // 片段 # +} + +// UrlParse 解析URl +func UrlParse(inputUrl string) (resp ResponseUrlParse) { + parse, err := url.Parse(inputUrl) + if err != nil { + return + } + resp.Scheme = parse.Scheme + resp.Hostname = parse.Hostname() + resp.Port = parse.Port() + resp.Path = parse.Path + resp.RawQuery = parse.RawQuery + resp.Fragment = parse.Fragment + return +}