summaryrefslogtreecommitdiff
path: root/plugins/static/config.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-14 09:19:00 +0300
committerValery Piashchynski <[email protected]>2021-05-14 09:19:00 +0300
commitf76b2392cd5b0c4e9f38736323a29b46f9451f0e (patch)
treeb463fd9267323bec1ed8a63f871686ed99843611 /plugins/static/config.go
parentfef96198ee6cc1f23bc869050944aa3071667ae7 (diff)
parente1ff9daead5033b537296ffb071e551b95af91ab (diff)
Merge remote-tracking branch 'origin/master' into feature/websockets-plugin
# Conflicts: # plugins/http/plugin.go # plugins/static/etag.go
Diffstat (limited to 'plugins/static/config.go')
-rw-r--r--plugins/static/config.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/plugins/static/config.go b/plugins/static/config.go
new file mode 100644
index 00000000..c3f9c17d
--- /dev/null
+++ b/plugins/static/config.go
@@ -0,0 +1,55 @@
+package static
+
+import (
+ "os"
+
+ "github.com/spiral/errors"
+)
+
+// Config describes file location and controls access to them.
+type Config struct {
+ Static *struct {
+ // Dir contains name of directory to control access to.
+ // Default - "."
+ Dir string
+
+ // CalculateEtag can be true/false and used to calculate etag for the static
+ CalculateEtag bool `mapstructure:"calculate_etag"`
+
+ // Weak etag `W/`
+ Weak bool
+
+ // forbid specifies list of file extensions which are forbidden for access.
+ // example: .php, .exe, .bat, .htaccess and etc.
+ Forbid []string
+
+ // Allow specifies list of file extensions which are allowed for access.
+ // example: .php, .exe, .bat, .htaccess and etc.
+ Allow []string
+
+ // Request headers to add to every static.
+ Request map[string]string
+
+ // Response headers to add to every static.
+ Response map[string]string
+ }
+}
+
+// Valid returns nil if config is valid.
+func (c *Config) Valid() error {
+ const op = errors.Op("static_plugin_valid")
+ st, err := os.Stat(c.Static.Dir)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return errors.E(op, errors.Errorf("root directory '%s' does not exists", c.Static.Dir))
+ }
+
+ return err
+ }
+
+ if !st.IsDir() {
+ return errors.E(op, errors.Errorf("invalid root directory '%s'", c.Static.Dir))
+ }
+
+ return nil
+}