-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
109 lines (105 loc) · 2.08 KB
/
test.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
package main
import (
"crypto/rand"
"fmt"
"math/big"
"reflect"
"time"
)
type asd struct {
a int
b []byte
c string
}
func nrand() int64 {
max := big.NewInt(int64(1) << 62)
bigx, _ := rand.Int(rand.Reader, max)
x := bigx.Int64()
return x
}
func (a *asd) asd(v1 interface{}, v2 interface{}) {
//t1 := reflect.TypeOf(v1)
//t := reflect.ValueOf(v1)
//fmt.Println(t1.Kind() == t2.Kind())
//fmt.Println(t1.Kind().String(), t2.Kind().String())
//asd, _ := t2.FieldByName("a")
//fmt.Println(t, t.FieldByName("b"))
aaa := (v1).(asd)
fmt.Println(aaa)
//for i := 0; i < t2.NumField(); i++ {
// fieldType := t2.Field(i)
// fmt.Printf("Tag: %v Type: %v Name:%v \n", fieldType.Tag, fieldType.Type, fieldType.Name)
//}
}
func main() {
//db := map[int]int{}
//db[1] = 11
//db[2] = 22
//val, ok := db[1]
//fmt.Println(val, ok)
//for a, b := range db {
// fmt.Println(a, b)
//}
//t := time.Now()
//for time.Since(t).Seconds() < 1 {
// time.Sleep(100 * time.Millisecond)
// fmt.Println(1)
//}
ch := make(chan int)
go func() {
time.Sleep(1500 * time.Millisecond)
ch <- 1
}()
tickTimer := time.NewTicker(1 * time.Second)
select {
case c := <-ch:
fmt.Println(c)
case <-tickTimer.C:
fmt.Println("over")
}
fmt.Println(11111)
a := asd{
a: 1,
}
mp := make(map[int]string)
mp[1] = mp[1]
fmt.Println(applyMsgToString(&a))
fmt.Println(a, mp)
var arr []int
arr = append(arr, 1)
arr = append(arr, 1)
arr = append(arr, 1)
arr = arr[:0]
fmt.Println(arr)
defer func() {
fmt.Println(111)
}()
defer func() {
fmt.Println(222)
}()
defer func() {
fmt.Println(333)
}()
//a := asd{
// c: "12",
//}
////fmt.Println(a.c == "")
//a.asd(a, 1)
//fmt.Println(raft.Raft{})
//t1 := reflect.TypeOf(a)
//t2 := reflect.TypeOf("1")
//fmt.Println(t1.Kind(), t2.Kind())
}
func applyMsgToString(msg *asd) string {
var str = ""
t := reflect.TypeOf(*msg)
v := reflect.ValueOf(*msg)
for i := 0; i < t.NumField(); i++ {
fieldType := t.Field(i)
str += fmt.Sprintf("%v: %v", fieldType.Name, v.FieldByName(fieldType.Name)) + " "
}
return str
}
func (a *asd) toString() string {
return "asd"
}