Add all dependency of go-getter

This commit is contained in:
Jingfang Liu
2018-08-15 11:34:38 -07:00
parent c9a8bc1121
commit ec95e5f97e
2894 changed files with 1945864 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
package sdkuri
import (
"path"
"strings"
)
// PathJoin will join the elements of the path delimited by the "/"
// character. Similar to path.Join with the exception the trailing "/"
// character is preserved if present.
func PathJoin(elems ...string) string {
if len(elems) == 0 {
return ""
}
hasTrailing := strings.HasSuffix(elems[len(elems)-1], "/")
str := path.Join(elems...)
if hasTrailing && str != "/" {
str += "/"
}
return str
}

View File

@@ -0,0 +1,21 @@
package sdkuri
import "testing"
func TestPathJoin(t *testing.T) {
cases := []struct {
Elems []string
Expect string
}{
{Elems: []string{"/"}, Expect: "/"},
{Elems: []string{}, Expect: ""},
{Elems: []string{"blah", "el", "blah/"}, Expect: "blah/el/blah/"},
{Elems: []string{"/asd", "asdfa", "asdfasd/"}, Expect: "/asd/asdfa/asdfasd/"},
{Elems: []string{"asdfa", "asdfa", "asdfads"}, Expect: "asdfa/asdfa/asdfads"},
}
for _, c := range cases {
if e, a := c.Expect, PathJoin(c.Elems...); e != a {
t.Errorf("expect %v, got %v", e, a)
}
}
}