-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
60 lines (49 loc) · 1.61 KB
/
helpers.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
package pprnt
import (
"fmt"
"reflect"
"strings"
)
var indentation int = 2
var lvl string = strings.Repeat("\t", indentation)
func _CreateLevelString() string {
return strings.Repeat(lvl, _state.Level)
}
func _ProcessArchitecture(arg interface{}, key, endChar *string) string {
value := reflect.ValueOf(arg)
if arg == nil {
return _PrintNil(arg, key, endChar)
}
switch reflect.TypeOf(arg).Kind() {
case reflect.Slice, reflect.Array:
return _PrintSliceOrArray(reflect.Indirect(value).Interface(), key, endChar)
case reflect.Map:
return _PrintMap(reflect.Indirect(value).Interface(), key, endChar)
case reflect.Struct:
return _PrintStruct(reflect.Indirect(value).Interface(), key, endChar)
// case reflect.Chan:
// case reflect.Interface:
case reflect.Ptr:
newValue := value.Elem()
newValue = reflect.Indirect(newValue)
return _ProcessArchitecture(newValue.Interface(), key, endChar)
// case reflect.UnsafePointer:
// case reflect.Uintptr:
}
return _PrintPrimitive(reflect.Indirect(value).Interface(), key, endChar)
}
func _PrintPrimitive(arg interface{}, key, endChar *string) string {
switch reflect.TypeOf(arg).Kind() {
case reflect.String:
return _PrintString(arg, key, endChar)
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return _PrintInt(arg, key, endChar)
case reflect.Bool:
return _PrintBoolean(arg, key, endChar)
case reflect.Float32, reflect.Float64:
return _PrintFloat(arg, key, endChar)
default:
fmt.Printf("[!!] %+v\n", arg)
return fmt.Sprintf("%+v\n", arg)
}
}