-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
106 lines (97 loc) · 2.55 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
package main
// @author [email protected]
// @date 2020/5/31 01:51
// @description
// @version
import (
"fmt"
//"net/http"
//_ "net/http/pprof" 可以动态监测pprof
"reflect"
"runtime"
"strings"
"github.com/WZZ1998/learn-go/feature"
)
var sepL = func() string {
fmt.Println("in main.go initializing var sepL")
return strings.Repeat("\n", 2) + strings.Repeat("-", 40)
}()
type F func()
func init() { // init函数会在包的最开始执行,这个函数不可以在代码中引用或者调用
fmt.Println("initializing package main......")
}
func main() {
//go func() {
// _ = http.ListenAndServe("localhost:8085", nil)
//}() // 开一个goroutine来监测程序的状态
//init() 不可以调用
var mainFunc F = main
//var initFunc F = init 无法引用到init
//mainFunc() 引发死递归
fmt.Printf("function main type v initFunc: %T\n\n", mainFunc)
learnFunctions := []func(){
feature.LearnMapOP,
feature.LearnString,
feature.LearnTypes,
feature.LearnRandom,
feature.LearnTime,
feature.LearnPointer,
feature.LearnControl,
feature.LearnFunction,
feature.LearnSlice,
feature.LearnMap,
feature.LearnLib,
feature.LearnStruct,
feature.LearnStruct2,
feature.LearnMethod,
feature.LearnMethod2,
feature.LearnInterface,
feature.LearnInterface2,
feature.LearnReflect,
feature.LearnReflect2,
feature.LearnSimpleFP,
//feature.LearnIO,
//feature.LearnIO2,
//feature.LearnIO3,
feature.LearnConcurrent,
feature.LearnJson,
feature.LearnCrypto,
feature.LearnException,
feature.LearnException2,
//feature.LearnSchedule, // 有for{} 除非trace,不要调用了
//feature.LearnMem,
feature.LearnMem2,
//feature.LearnMem3,
feature.LearnGoroutine,
feature.LearnAlgUse,
feature.LearnIterate,
//golang 编译器的一个bug,已经从github上拿到了1.14.7的源代码,改了path, 不再有这个问题
// 关于后续的优化: https://github.com/golang/go/issues/40502
feature.LearnUnsafe,
feature.LearnGoroutine2,
feature.LearnChan,
//feature.LearnChan2, //慢
feature.LearnTimer,
feature.LearnChan3,
feature.LearnServer,
//feature.LearnGoroutine3, // 慢
//feature.LearnGoroutineBench, 有bench
feature.LearnSafeObj,
feature.LearnCode,
feature.LearnContext,
}
for _, lf := range learnFunctions {
fmt.Println(getFuncNameWithFV(lf))
fmt.Println()
lf()
printSeparatingLine()
}
}
func printSeparatingLine() {
fmt.Println(sepL)
}
func getFuncNameWithFV(fToGetName func()) string {
vPtr := reflect.ValueOf(fToGetName).Pointer()
pf := runtime.FuncForPC(vPtr)
return pf.Name()
}