diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 7e5158b..96ad886 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -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 { diff --git a/lib/tools/tools_test.go b/lib/tools/tools_test.go index bf7b7f1..cb6fd37 100644 --- a/lib/tools/tools_test.go +++ b/lib/tools/tools_test.go @@ -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.") + } +}