本文整理汇总了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 += "/"
}
}
示例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
}
}
示例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
}
示例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
}
示例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
}
示例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
}