/
tools.go
61 lines (53 loc) · 1.31 KB
/
tools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ==========================================================================
Golib Repo
Filename: tools.go
Owner: Sergiy Safronov
Source : github.com/CoderSergiy/golib/tools
Purpose: Utils methods
=============================================================================
*/
package tools
/****************************************************************************************
*
* Function : EnsureSlashInEnd
*
* Purpose : Ensure slesh is presents in the end of string
*
* Input : url string - string to check
*
* Return : string with slesh in the end
*/
func EnsureSlashInEnd(url string) string {
if len(url) == 0 {
return (url)
}
if url[len(url)-1] == '/' {
return url
}
return (url + "/")
}
/****************************************************************************************
*
* Function : Implode
*
* Purpose : Convert string array to one line with separators
*
* Input : array []string - income string
* separator ...byte - set separator if need it (',' by default)
*
* Return : string
*/
func Implode(array []string, separator ...byte) string {
var sep byte = ','
if len(separator) > 0 {
sep = separator[0]
}
var output string
for _, word := range array {
if len(output) > 0 {
output = output + string(sep)
}
output = output + word
}
return output
}