-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
148 lines (134 loc) · 2.73 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"fmt"
"go-playground/datastructure/linearlist/linkedlist"
"io/ioutil"
"log"
"math"
"os"
"path/filepath"
"reflect"
"runtime"
)
func main() {
//m := map[string]int{"1": 1,"2": 2}
//mp2 := make(map[int]*[]int)
//sub := []int{1, 2, 3, 4}
//mp2[1] = &sub
//delete(mp2, 1)
//fmt.Print(mp2)
//linkedlist_test()
var bool bool
//blank := isBlank(reflect.ValueOf(a))
fmt.Print(bool)
//go fmt.Print("1")
loadKubeConfig()
}
func loadKubeConfig() {
abs, _ := filepath.Abs("std-lib-test")
dir, _ := ioutil.ReadDir(abs)
for _, f := range dir {
s, _ := filepath.Abs(f.Name())
file, _ := os.ReadFile(s)
fmt.Println(file)
}
}
func isBlank(value reflect.Value) bool {
switch value.Kind() {
case reflect.String:
return value.Len() == 0
case reflect.Bool:
return !value.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return value.Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return value.Uint() == 0
case reflect.Float32, reflect.Float64:
return value.Float() == 0
case reflect.Interface, reflect.Ptr:
return value.IsNil()
}
return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
}
func IsNil(i interface{}) bool {
vi := reflect.ValueOf(i)
if vi.Kind() == reflect.Ptr {
return vi.IsNil()
}
return false
}
func linkedlist_test() {
linkedlist := linkedlist.EmptyLinkedlist()
linkedlist.TailAdd("1")
linkedlist.TailAdd("2")
linkedlist.TailAdd("3")
linkedlist.TailAdd("4")
linkedlist.Reverse()
}
func slice_test() {
//b:= []string{"g", "o", "l", "a", "t", "f"}
//ints := b[0:3]
i := []int{1, 2, 3}
b := make([]int, 3)
b[0] = 1
fmt.Print(i[1:])
//for _, item := range j {
// item *= 2
// fmt.Print(item)
//}
//b = b[:1]
//fmt.Print(b)'
}
func doSth(a *int) {
b := a
fmt.Printf("b: %s \n", b)
c := &a
fmt.Printf("c: %s \n", c)
}
func returnVal() {
sqrt, ok := mySqrt(-0.0001)
if ok {
fmt.Printf("%s\n,%s\n", sqrt, ok)
}
fmt.Printf("%s\n", &ok)
}
func switch_test() {
k := 6
switch k {
case 4:
fmt.Printf("%s \n", "was <= 4")
case 5:
fmt.Printf("%s \n", "was <= 5")
case 6:
fmt.Printf("%s \n", "was <= 6")
fallthrough
case 7:
fmt.Printf("%s\n", "was <= 7")
case 8:
fmt.Printf("%s \n", "was <= 8")
default:
fmt.Printf("%s \n", "default case")
}
}
func mySqrt(f float64) (v float64, ok bool) {
if f < 0 {
return
} // error case
return math.Sqrt(f), true
}
func init() {
fmt.Printf("%s \n", "===============================")
}
func defertest() {
i := 0
defer fmt.Printf("===========> %d \n", i)
i++
return
}
func debug_test() {
where := func() {
_, file, line, _ := runtime.Caller(1)
log.Printf("%s:%d", file, line)
}
where()
}