summaryrefslogtreecommitdiff
path: root/service/static/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'service/static/config.go')
-rw-r--r--service/static/config.go34
1 files changed, 22 insertions, 12 deletions
diff --git a/service/static/config.go b/service/static/config.go
index 1020b8cd..95fdbeee 100644
--- a/service/static/config.go
+++ b/service/static/config.go
@@ -2,6 +2,7 @@ package static
import (
"github.com/pkg/errors"
+ "github.com/spiral/roadrunner/service"
"os"
"path"
"strings"
@@ -20,22 +21,18 @@ type Config struct {
Forbid []string
}
-// Forbids must return true if file extension is not allowed for the upload.
-func (cfg *Config) Forbids(filename string) bool {
- ext := strings.ToLower(path.Ext(filename))
-
- for _, v := range cfg.Forbid {
- if ext == v {
- return true
- }
+// Hydrate must populate Config values using given Config source. Must return error if Config is not valid.
+func (c *Config) Hydrate(cfg service.Config) error {
+ if err := cfg.Unmarshal(c); err != nil {
+ return err
}
- return false
+ return c.Valid()
}
-// Valid validates existence of directory.
-func (cfg *Config) Valid() error {
- st, err := os.Stat(cfg.Dir)
+// Valid returns nil if config is valid.
+func (c *Config) Valid() error {
+ st, err := os.Stat(c.Dir)
if err != nil {
if os.IsNotExist(err) {
return errors.New("root directory does not exists")
@@ -50,3 +47,16 @@ func (cfg *Config) Valid() error {
return nil
}
+
+// Forbids must return true if file extension is not allowed for the upload.
+func (c *Config) Forbids(filename string) bool {
+ ext := strings.ToLower(path.Ext(filename))
+
+ for _, v := range c.Forbid {
+ if ext == v {
+ return true
+ }
+ }
+
+ return false
+}