config/url_config: extract paths() function
This commit is contained in:
parent
fdbf3041f9
commit
0b95e7c8b5
@ -36,15 +36,8 @@ func (c *URLConfig) get(key, rawurl string) (string, bool) {
|
||||
}
|
||||
|
||||
hosts := c.hosts(u)
|
||||
paths := c.paths(u.Path)
|
||||
|
||||
pLen := len(u.Path)
|
||||
if pLen > 2 {
|
||||
end := pLen
|
||||
if strings.HasSuffix(u.Path, "/") {
|
||||
end -= 1
|
||||
}
|
||||
|
||||
paths := strings.Split(u.Path[1:end], "/")
|
||||
for i := len(paths); i > 0; i-- {
|
||||
for _, host := range hosts {
|
||||
path := strings.Join(paths[:i], "/")
|
||||
@ -56,7 +49,6 @@ func (c *URLConfig) get(key, rawurl string) (string, bool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, host := range hosts {
|
||||
if v, ok := c.git.Get(fmt.Sprintf("http.%s.%s", host, key)); ok {
|
||||
@ -80,3 +72,16 @@ func (c *URLConfig) hosts(u *url.URL) []string {
|
||||
|
||||
return hosts
|
||||
}
|
||||
|
||||
func (c *URLConfig) paths(path string) []string {
|
||||
pLen := len(path)
|
||||
if pLen <= 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
end := pLen
|
||||
if strings.HasSuffix(path, "/") {
|
||||
end -= 1
|
||||
}
|
||||
return strings.Split(path[1:end], "/")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user