-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultipart.go
76 lines (66 loc) · 1.67 KB
/
multipart.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
package essen
import (
"log"
"path/filepath"
)
//Paths for uploaded files
type uploadParam map[string]string
func (u uploadParam) push(key string, value string) uploadParam {
if u != nil {
u[key] = value
} else {
u = make(uploadParam)
u[key] = value
return u
}
return nil
}
//Close method is used to clear request related data (Mostly Multipart Data)
//
// req.Close()
func (r Request) Close() {
_, ok := uploadedPaths[r.Uid]
if ok {
delete(uploadedPaths, r.Uid)
}
}
var uploadedPaths = make(map[string]uploadParam)
//isSet
var isSet = false
//MultiPartConfig map is used to store configuration data for multipart requests.
var MultiPartConfig = map[string]string{"UploadDir": Defaults.UploadDir} //optional
//SetMultiPartConfig function is used to set multipart requests configuration
//
//It can be set directly by changing MultiPartConfig map but calling this function is recommended way of doing so.
//
// app := essen.App()
// app.SetMultiPartConfig(map[string]string{"UploadDir": "./uploadsFolder"}) //optional
func (e Essen) SetMultiPartConfig(configMap map[string]string) bool {
if configMap["UploadDir"] == "" {
configMap["UploadDir"] = Defaults.UploadDir
}
absPath, err := filepath.Abs(configMap["UploadDir"])
if err != nil {
log.Fatal(err.Error())
}
configMap["UploadDir"] = absPath
ee := CreateDirIfNotExist(configMap["UploadDir"])
if !ee.IsNil() {
log.Fatal(ee.Error())
}
MultiPartConfig = configMap
isSet = true
return true
}
//Config is set
func mConfigIsSet() bool {
return isSet
}
//Create Upload Directory
func setDefaultConfig() {
ee := CreateDirIfNotExist(Defaults.UploadDir)
if !ee.IsNil() {
log.Panic(ee.Error())
}
isSet = true
}