-
Notifications
You must be signed in to change notification settings - Fork 15
/
24vistor.go
155 lines (139 loc) · 2.63 KB
/
24vistor.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
149
150
151
152
153
154
155
/**
@author: Jason Pang
@desc:
@date: 2021/8/11
**/
package design
import "fmt"
/**
* @Author: Jason Pang
* @Description: 读文件接口,用于获取到文件
*/
type ReadFile interface {
Read(fileName string)
Accept(v VistorReadFile)
}
/**
* @Author: Jason Pang
* @Description: 读pdf文件类
*/
type ReadPdfFile struct {
}
/**
* @Author: Jason Pang
* @Description: 读取文件
* @receiver p
* @param fileName
*/
func (p *ReadPdfFile) Read(fileName string) {
fmt.Println("读取pdf文件" + fileName)
}
/**
* @Author: Jason Pang
* @Description: 接受访问者类
* @receiver p
* @param v
*/
func (p *ReadPdfFile) Accept(v VistorReadFile) {
v.VistorPdfFile(p)
}
/**
* @Author: Jason Pang
* @Description: 读取txt文件类
*/
type ReadTxtFile struct {
}
/**
* @Author: Jason Pang
* @Description: 读取文件
* @receiver t
* @param fileName
*/
func (t *ReadTxtFile) Read(fileName string) {
fmt.Println("读取txt文件" + fileName)
}
/**
* @Author: Jason Pang
* @Description: 接受访问者类
* @receiver p
* @param v
*/
func (t *ReadTxtFile) Accept(v VistorReadFile) {
v.VistorTxtFile(t)
}
/**
* @Author: Jason Pang
* @Description: 访问者,包含对pdf和txt的操作
*/
type VistorReadFile interface {
VistorPdfFile(p *ReadPdfFile)
VistorTxtFile(t *ReadTxtFile)
}
/**
* @Author: Jason Pang
* @Description: 提取文件类
*/
type ExactFile struct {
}
/**
* @Author: Jason Pang
* @Description: 提取pdf文件
* @receiver e
* @param p
*/
func (e *ExactFile) VistorPdfFile(p *ReadPdfFile) {
fmt.Println("提取pdf文件内容")
}
/**
* @Author: Jason Pang
* @Description: 提取txt文件
* @receiver e
* @param p
*/
func (e *ExactFile) VistorTxtFile(p *ReadTxtFile) {
fmt.Println("提取txt文件内容")
}
/**
* @Author: Jason Pang
* @Description: 压缩文件类
*/
type CompressionFile struct {
}
/**
* @Author: Jason Pang
* @Description: 压缩pdf文件
* @receiver c
* @param p
*/
func (c *CompressionFile) VistorPdfFile(p *ReadPdfFile) {
fmt.Println("压缩pdf文件内容")
}
/**
* @Author: Jason Pang
* @Description: 压缩txt文件
* @receiver c
* @param p
*/
func (c *CompressionFile) VistorTxtFile(p *ReadTxtFile) {
fmt.Println("压缩txt文件内容")
}
func vistorMain() {
filesList := []ReadFile{
&ReadPdfFile{},
&ReadTxtFile{},
&ReadPdfFile{},
&ReadTxtFile{},
}
//提取文件
fmt.Println("--------------------------提取文件")
extract := ExactFile{}
for _, f := range filesList {
f.Accept(&extract)
}
//压缩文件
fmt.Println("--------------------------压缩文件")
compress := CompressionFile{}
for _, f := range filesList {
f.Accept(&compress)
}
}