summaryrefslogtreecommitdiff
path: root/service/static/config.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-08 13:06:05 -0700
committerWolfy-J <[email protected]>2018-07-08 13:06:05 -0700
commit29c9bf94350e86ec96f5ce5eeb476dfcd57302cd (patch)
tree9f59af6446958d144b7de91b5005a3727dc90661 /service/static/config.go
parent3c3a7801100f29c99a5e446646c818bf16ccd5f0 (diff)
dependency injection and lighter service Init methods.
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..6a2d1206 100644
--- a/service/static/config.go
+++ b/service/static/config.go
@@ -5,6 +5,7 @@ import (
"os"
"path"
"strings"
+ "github.com/spiral/roadrunner/service"
)
// Config describes file location and controls access to them.
@@ -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
+}