加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

老9乐购下载最高邀请码 25295678,golang net/url包使用

发布时间:2020-12-16 09:26:42 所属栏目:大数据 来源:网络整理
导读:.net/url简介 import "net/url" url包解析URL并实现查询转义 URL结构体 // Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/. // A consequence is that it is impossible to tell which slashes in the Path were // slashes
.net/url简介
import "net/url"
url包解析URL并实现查询转义

URL结构体
// Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.
// A consequence is that it is impossible to tell which slashes in the Path were
// slashes in the raw URL and which were %2f. This distinction is rarely important,
// but when it is,code must not use Path directly.
// The Parse function sets both Path and RawPath in the URL it returns,
// and URL‘s String method uses RawPath if it is a valid encoding of Path,
// by calling the EscapedPath method.
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
老9乐购下载最高邀请码 25295678

Path       string    // path (relative paths may omit leading slash)
RawPath    string    // encoded path hint (see EscapedPath method)
ForceQuery bool      // append a query (‘?‘) even if RawQuery is empty
RawQuery   string    // encoded query values,without ‘?‘
Fragment   string    // fragment for references,without ‘#‘

}
func Parse(rawurl string) (*URL,error)
将原生的rawurl字符串解析成URL结构体
package main

import (
"fmt"
"log"
"net/url"
)

func main() {
u,err := url.Parse("http://www.baidu.com/search?q=dotnet")if err != nil {log.Fatal(err)}u.Scheme = "https"u.Host = "google.com"q := u.Query()q.Set("q","golang")u.RawQuery = q.Encode()fmt.Println(u)}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读