Не добавляем домен к ссылке на скин, если скин уже имеет домен

This commit is contained in:
ErickSkrauch 2017-04-13 14:20:04 +03:00
parent f610667aa5
commit b22f0551fa
2 changed files with 16 additions and 1 deletions

View File

@ -30,7 +30,12 @@ func BuildKey(username string) string {
}
func BuildElyUrl(route string) string {
return "http://ely.by" + route
prefix := "http://ely.by"
if !strings.HasPrefix(route, prefix) {
route = prefix + route
}
return route
}
func getCurrentHour() int64 {

View File

@ -20,3 +20,13 @@ func TestBuildKey(t *testing.T) {
t.Error("Function shound convert string to lower case and concatenate it with usernmae:")
}
}
func TestBuildElyUrl(t *testing.T) {
if BuildElyUrl("/route") != "http://ely.by/route" {
t.Error("Function should add prefix to the provided relative url.")
}
if BuildElyUrl("http://ely.by/test/route") != "http://ely.by/test/route" {
t.Error("Function should do not add prefix to the provided prefixed url.")
}
}