1 Star 3 Fork 1

Joshua Conero / uymas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
url.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/conero/uymas.git
git@gitee.com:conero/uymas.git
conero
uymas
uymas
v1.1.0-ea3

搜索帮助

344bd9b3 5694891 D2dac590 5694891