Total Lines | 21 |
Duplicated Lines | 0 % |
Changes | 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 |