-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoApp.go
141 lines (111 loc) · 2.75 KB
/
goApp.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
package main
import (
"GoApp/db"
"GoApp/dirMonitor"
"GoApp/fileDeal"
"GoApp/oop"
"bufio"
//"bytes"
//"encoding/json"
"fmt"
"os"
)
func main() {
input := initAppConsole()
chooseMethod(input)
}
func initAppConsole() string {
fmt.Println("*****************************")
fmt.Println("* Welcom GoApp ...... *")
fmt.Println("* 1 FileDeal *")
fmt.Println("* 2 SortInterface *")
fmt.Println("* 3 OOP *")
fmt.Println("* 4 FileDealToDB *")
fmt.Println("* 5 DirMonitor *")
fmt.Println("* 0 exit *")
fmt.Println("*****************************")
fmt.Println("Please choose function code : ")
reader := bufio.NewReader(os.Stdin)
input, _, _ := reader.ReadLine()
return string(input)
}
type SiginChan struct {
Id int
msg string
}
func chooseMethod(input string) {
switch input {
case "1":
flag := fileDeal.ReadFileAndPrint()
if flag {
sr := initAppConsole()
chooseMethod(sr)
} else {
sr := initAppConsole()
chooseMethod(sr)
}
case "2":
c := make(chan interface{})
go func() {
ints := oop.Xi{100, 78, 99, 30, 101}
strings := oop.Si{"111", "333", "abc", "0"}
oop.Sort(ints)
fmt.Printf("%v\n", ints)
oop.Sort(strings)
fmt.Printf("%v\n", strings)
c <- 1
c <- "test"
c <- &SiginChan{1, "success"}
c <- &SiginChan{0, "error"}
close(c)
}()
for v := range c {
fmt.Println("c value :", v)
}
sr := initAppConsole()
chooseMethod(sr)
case "3":
mf := oop.MyFile{}
sf := mf.InitMyFile()
fmt.Print("%v\n", sf)
case "4":
fileDb := fileDeal.DataFile{}
fileInfo := fileDb.FileInfoInit("textFile.csv")
fmt.Printf("%v\n", fileInfo)
//buffer := bytes.NewBuffer(nil)
//encoder := json.NewEncoder(buffer)
//encoder.Encode(fileInfo)
//fmt.Printf("%v\n", buffer)
db.InsertMysql(&fileInfo, "insert into go_insert(C1,C2,C3,C4)VALUES(?,?,?,?)")
case "5":
fmt.Println("Please input Dir Path:")
reader := bufio.NewReader(os.Stdin)
input, _, _ := reader.ReadLine()
dirMontor(string(input))
case "6":
//dirMonitor.PathWalk("F://GoSpace//src//GoApp")
case "0":
os.Exit(0)
default:
fmt.Println("input error,please try again!")
reader := bufio.NewReader(os.Stdin)
tmp, _, _ := reader.ReadLine()
chooseMethod(string(tmp))
}
}
func dirMontor(dirName string) {
ch := make(chan dirMonitor.DirInfo)
info1 := dirMonitor.DirInfo{}
begin := info1.PathWalk(dirName)
go info1.DirMonitor(dirName, ch)
for v := range ch {
if dirMonitor.DirWaklCompare(v, begin) {
//fmt.Println("==============================")
//fmt.Println("Dir not change......")
} else {
begin = info1.PathWalk(dirName)
fmt.Println("Dir is change......")
fmt.Println("==============================")
}
}
}