-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.go
55 lines (51 loc) · 1.11 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
package main
import(
"strconv"
)
//Tools ----------------------------------------------------------
type Tools struct{
getStrAry toolsGetStrAry
getStr toolsGetStr
getInt toolsGetInt
}
var tools Tools
//getInt
type toolsGetInt struct{}
//getInt.fromStr
func (*toolsGetInt) fromStr(fromStr string)(resInt int, err error){
resInt, err = strconv.Atoi(fromStr)
if err!= nil{
logger.Printf(err.Error())
return 0, err
}
return
}
//getStr
type toolsGetStr struct{}
//getStr.fromInt
func (*toolsGetStr) fromInt(fromInt int)(resStr string){
return strconv.Itoa(fromInt)
}
//getStrAry
type toolsGetStrAry struct{}
//getStrAry.noDuplicate
func (*toolsGetStrAry) noDuplicate(strAry []string) (res []string){
noDuplicate := make(map[string]bool)
for _, str := range strAry {
if _, wasInserted := noDuplicate[str]; !wasInserted {
noDuplicate[str]=true
res = append(res, str)
}
}
return res
}
//getStrAry.combind
func (*toolsGetStrAry) combind(strAry1 []string, strAry2 []string)(res []string){
for _,str := range strAry1{
res = append(res,str)
}
for _,str := range strAry2{
res = append(res,str)
}
return res
}