pkg/common/urlpath/join.go   A
last analyzed

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A urlpath.Join 0 10 3
1
package urlpath
2
3
import (
4
	"path"
5
	"strings"
6
)
7
8
// Join joins any number of path elements into a single path, adding a
9
// separating slash if necessary. The result is Cleaned; in particular,
10
// all empty strings are ignored.
11
// If the last element end in a slash it will preserve it.
12
func Join(elem ...string) string {
13
	joined := path.Join(elem...)
14
15
	last := elem[len(elem)-1]
16
17
	if strings.HasSuffix(last, "/") && !strings.HasSuffix(joined, "/") {
18
		joined += "/"
19
	}
20
21
	return joined
22
}
23