...
1 package resourcename
2
3 import (
4 "fmt"
5 "strings"
6 )
7
8
9 func Join(elems ...string) string {
10 segments := make([]string, 0, len(elems))
11 for elemIndex, elem := range elems {
12 var sc Scanner
13 sc.Init(elem)
14
15 for sc.Scan() {
16 if elemIndex == 0 && len(segments) == 0 && sc.Full() {
17 segments = append(segments, fmt.Sprintf("//%s", sc.ServiceName()))
18 }
19
20 segment := sc.Segment()
21 if segment == "" {
22 continue
23 }
24 segments = append(segments, string(segment))
25 }
26 }
27
28 if len(segments) == 0 {
29 return "/"
30 }
31
32 return strings.Join(segments, "/")
33 }
34
View as plain text