urlpath.Join   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
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