當前位置: 首頁>>代碼示例>>Golang>>正文


Golang URL.RawPath方法代碼示例

本文整理匯總了Golang中net/url.URL.RawPath方法的典型用法代碼示例。如果您正苦於以下問題:Golang URL.RawPath方法的具體用法?Golang URL.RawPath怎麽用?Golang URL.RawPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/url.URL的用法示例。


在下文中一共展示了URL.RawPath方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cleanPath

func cleanPath(u *url.URL) {
	hasSlash := strings.HasSuffix(u.Path, "/")

	// clean up path, removing duplicate `/`
	u.Path = path.Clean(u.Path)
	u.RawPath = path.Clean(u.RawPath)

	if hasSlash && !strings.HasSuffix(u.Path, "/") {
		u.Path += "/"
		u.RawPath += "/"
	}
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:12,代碼來源:build.go

示例2: Expand

// Expand subsitutes any {encoded} strings in the URL passed in using
// the map supplied.
//
// This calls SetOpaque to avoid encoding of the parameters in the URL path.
func Expand(u *url.URL, expansions map[string]string) {
	escaped, unescaped, err := uritemplates.Expand(u.Path, expansions)
	if err == nil {
		u.Path = unescaped
		u.RawPath = escaped
	}
}
開發者ID:jfrazelle,項目名稱:s3server,代碼行數:11,代碼來源:googleapi.go

示例3: buildURI

func buildURI(u *url.URL, v reflect.Value, name string) error {
	value, err := convertType(v)
	if err == errValueNotSet {
		return nil
	} else if err != nil {
		return awserr.New("SerializationError", "failed to encode REST request", err)
	}

	u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1)
	u.Path = strings.Replace(u.Path, "{"+name+"+}", value, -1)

	u.RawPath = strings.Replace(u.RawPath, "{"+name+"}", EscapePath(value, true), -1)
	u.RawPath = strings.Replace(u.RawPath, "{"+name+"+}", EscapePath(value, false), -1)

	return nil
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:16,代碼來源:build.go

示例4: newResetLevelsEndpoint

func newResetLevelsEndpoint(URL url.URL, path string) endpoint.Endpoint {
	URL.Path = path
	URL.RawPath = path

	newEndpoint := httptransport.NewClient(
		"POST",
		&URL,
		resetLevelsEncoder,
		resetLevelsDecoder,
	).Endpoint()

	return newEndpoint
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:13,代碼來源:endpoint.go

示例5: newSetVerbosityEndpoint

func newSetVerbosityEndpoint(URL url.URL, path string) endpoint.Endpoint {
	URL.Path = path
	URL.RawPath = path

	newEndpoint := httptransport.NewClient(
		"POST",
		&URL,
		setVerbosityEncoder,
		setVerbosityDecoder,
	).Endpoint()

	return newEndpoint
}
開發者ID:xh3b4sd,項目名稱:anna,代碼行數:13,代碼來源:endpoint.go

示例6: Normalize

func Normalize(u *url.URL) error {
	if !utf8.ValidString(u.String()) {
		return fmt.Errorf("normalize URL: invalid UTF-8 string: %q", u.String())
	}

	u.Scheme = strings.ToLower(u.Scheme)
	if u.Scheme != "http" && u.Scheme != "https" {
		return fmt.Errorf("normalize URL: unsupported scheme: %v", u.Scheme)
	}
	host, port, err := net.SplitHostPort(u.Host)
	if err != nil { // missing port
		host, port = u.Host, ""
	}
	if host == "" {
		return errors.New("normalize URL: empty host")
	} else if v, err := validateHost(host); err != nil {
		return fmt.Errorf("normalize URL: invalid host %q: %v", host, err)
	} else {
		u.Host = v
	}

	if (u.Scheme == "http" && port == "80") ||
		(u.Scheme == "https" && port == "443") {
		port = ""
	}
	if port != "" {
		u.Host = net.JoinHostPort(u.Host, port)
	}

	clean := func(pth string) string {
		p := path.Clean(pth)
		if p == "." {
			p = ""
		} else if strings.HasSuffix(pth, "/") && !strings.HasSuffix(p, "/") {
			p += "/"
		}
		return p
	}
	u.Path = clean(u.Path)
	u.RawPath = clean(u.RawPath)
	u.Fragment = ""
	return nil
}
開發者ID:fanyang01,項目名稱:crawler,代碼行數:43,代碼來源:normalize.go


注:本文中的net/url.URL.RawPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。