代码拉取完成,页面将自动刷新
package str
import (
"net/url"
"path"
"strings"
)
/**
* @DATE 2019/6/3
* @NAME Joshua Conero
* @DESCRIPIT Url 带命名空间的 URL 处理类
**/
// Url only any the url methods of namespace
type Url struct {
}
// AbsHref Get the absolute address of the path: path address path, URL is the top-level path, which can be empty
// BUG(AbsHref): Url.AbsHref 中解析 "vpath" `test/p1/p2` 与 `./test/p1/p2` 的一致性问题
func (u Url) AbsHref(vpath, vurl string) string {
var href string
// 需要解析, vurl 含 http(s)://
if strings.Index(vurl, "http://") > -1 || strings.Index(vurl, "https://") > -1 {
if u, err := url.Parse(vurl); err == nil {
uHost := u.Scheme + "://" + u.Host
// 字符连接处检测
uFirstChar := ""
if len(vpath) > 0 {
uFirstChar = vpath[0:1]
}
if uFirstChar == "/" {
href = uHost + path.Clean(vpath)
} else {
nS := u.Path + "/" + vpath
nS = path.Clean(nS)
href = uHost + nS
}
}
} else {
href = path.Clean(href)
}
return href
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。