This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
values_file.go
72 lines (61 loc) · 1.65 KB
/
values_file.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
package form
import (
"mime/multipart"
)
/*
Implement:
ValuesInterface
ValuesFileInterface
*/
type valuesFile struct {
values *multipart.Form
valuesCount map[string]int
fileCount map[string]int
}
func newValuesFile(form *multipart.Form) *valuesFile {
return &valuesFile{
values: form,
valuesCount: map[string]int{},
fileCount: map[string]int{},
}
}
func (v *valuesFile) valueIncrement(name string) {
v.valuesCount[name]++
}
func (v *valuesFile) GetOne(name string) string {
if nil == v.values.Value[name] || v.valuesCount[name] >= len(v.values.Value[name]) {
return ""
}
defer v.valueIncrement(name)
return v.values.Value[name][v.valuesCount[name]]
}
func (v *valuesFile) valueMarkAll(name string) {
v.valuesCount[name] = len(v.values.Value[name])
}
func (v *valuesFile) GetAll(name string) []string {
if nil == v.values.Value[name] || v.valuesCount[name] >= len(v.values.Value[name]) {
return nil
}
defer v.valueMarkAll(name)
return v.values.Value[name][v.valuesCount[name]:]
}
func (v *valuesFile) fileIncrement(name string) {
v.fileCount[name]++
}
func (v *valuesFile) GetOneFile(name string) *multipart.FileHeader {
if nil == v.values.File[name] || v.fileCount[name] >= len(v.values.File[name]) {
return nil
}
defer v.fileIncrement(name)
return v.values.File[name][v.fileCount[name]]
}
func (v *valuesFile) fileMarkAll(name string) {
v.fileCount[name] = len(v.values.File[name])
}
func (v *valuesFile) GetAllFile(name string) []*multipart.FileHeader {
if nil == v.values.File[name] || v.fileCount[name] >= len(v.values.File[name]) {
return nil
}
defer v.fileMarkAll(name)
return v.values.File[name][v.fileCount[name]:]
}