summaryrefslogtreecommitdiff
path: root/service/http/uploads_config.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-10 17:04:02 +0300
committerWolfy-J <[email protected]>2018-06-10 17:04:02 +0300
commit3fe85e9d92f5f98337e8f7fd9a14e6b66b9694bd (patch)
tree2575fbba16df4f95dd392f231ad7d7b30a5dd4ef /service/http/uploads_config.go
parent4c292ee46f5505b00b16186e8f30e9bc1be25895 (diff)
http service
Diffstat (limited to 'service/http/uploads_config.go')
-rw-r--r--service/http/uploads_config.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/service/http/uploads_config.go b/service/http/uploads_config.go
new file mode 100644
index 00000000..ac80723f
--- /dev/null
+++ b/service/http/uploads_config.go
@@ -0,0 +1,29 @@
+package http
+
+import (
+ "strings"
+ "path"
+)
+
+// UploadsConfig describes file location and controls access to them.
+type UploadsConfig struct {
+ // Dir contains name of directory to control access to.
+ Dir string
+
+ // Forbid specifies list of file extensions which are forbidden for access.
+ // Example: .php, .exe, .bat, .htaccess and etc.
+ Forbid []string
+}
+
+// Forbid must return true if file extension is not allowed for the upload.
+func (cfg UploadsConfig) Forbids(filename string) bool {
+ ext := strings.ToLower(path.Ext(filename))
+
+ for _, v := range cfg.Forbid {
+ if ext == v {
+ return true
+ }
+ }
+
+ return false
+}