-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
49 lines (44 loc) · 1017 Bytes
/
util.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
package main
import (
"fmt"
"log"
)
// getType checks whether the data types are the same. If same it returns
// data type concatenated with its dimention(2D/3D). If the data type is not same
// then it returns interface{} concatenated with its dimention(2D/3D).
func getType(types []string, level int) string {
var i int
var l string = getDiamentionOfSlice(level)
for i < len(types)-1 {
if types[i] != types[i+1] {
return l + "interface{}"
}
i++
}
return l + types[0]
}
// getDiamentionOfSlice returns the dimention of the Slice based on the level.
// it can be 2D, 3D etc
func getDiamentionOfSlice(level int) string {
var output string
for level > 0 {
output += fmt.Sprintf("[]")
level--
}
return output
}
// printTabs returns the number of tabs to put in front of each line based on the level.
func printTabs(count int) string {
var i int
var result string
for i < count {
result += "\t"
i++
}
return result
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}