mirror of
https://github.com/hacdias/webdav.git
synced 2024-04-21 12:32:06 +00:00
fix: pass through linters
License: MIT Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
+1
-1
@@ -9,4 +9,4 @@ func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-7
@@ -126,14 +126,12 @@ func parseCors(raw []interface{}, c *webdav.Config) {
|
||||
if cfg, ok := v.(map[interface{}]interface{}); ok {
|
||||
|
||||
cors := webdav.CorsCfg{
|
||||
Enabled: cfg["enabled"].(bool),
|
||||
Enabled: cfg["enabled"].(bool),
|
||||
AllowedHosts: []string{},
|
||||
}
|
||||
|
||||
if allowed_hosts, ok := cfg["allowed_hosts"]; ok {
|
||||
for _, host := range strings.Split(allowed_hosts.(string), ",") {
|
||||
hosts = append(hosts, host)
|
||||
}
|
||||
if allowedHosts, ok := cfg["allowed_hosts"]; ok {
|
||||
hosts = append(hosts, strings.Split(allowedHosts.(string), ",")...)
|
||||
}
|
||||
|
||||
if len(hosts) == 0 {
|
||||
@@ -157,9 +155,9 @@ func readConfig(flags *pflag.FlagSet) *webdav.Config {
|
||||
LockSystem: wd.NewMemLS(),
|
||||
},
|
||||
},
|
||||
Auth: getOptB(flags, "auth"),
|
||||
Auth: getOptB(flags, "auth"),
|
||||
Cors: webdav.CorsCfg{
|
||||
Enabled: false,
|
||||
Enabled: false,
|
||||
AllowedHosts: []string{},
|
||||
},
|
||||
Users: map[string]*webdav.User{},
|
||||
|
||||
+6
-6
@@ -16,10 +16,10 @@ func checkPassword(saved, input string) bool {
|
||||
}
|
||||
|
||||
func isAllowedHost(allowedHosts []string, origin string) bool {
|
||||
for _, host := range allowedHosts {
|
||||
if host == origin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
for _, host := range allowedHosts {
|
||||
if host == origin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
+6
-6
@@ -6,17 +6,17 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Config is the configuration of a WebDAV instance.
|
||||
|
||||
// CorsCfg is the CORS config.
|
||||
type CorsCfg struct {
|
||||
Enabled bool
|
||||
Enabled bool
|
||||
AllowedHosts []string
|
||||
}
|
||||
|
||||
// Config is the configuration of a WebDAV instance.
|
||||
type Config struct {
|
||||
*User
|
||||
Auth bool
|
||||
Cors CorsCfg
|
||||
Cors CorsCfg
|
||||
Users map[string]*User
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ func (c *Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
headers := w.Header()
|
||||
|
||||
if(len(c.Cors.AllowedHosts) == 1 && c.Cors.AllowedHosts[0] == "*") {
|
||||
if len(c.Cors.AllowedHosts) == 1 && c.Cors.AllowedHosts[0] == "*" {
|
||||
headers.Set("Access-Control-Allow-Methods", "*")
|
||||
headers.Set("Access-Control-Allow-Headers", "*")
|
||||
headers.Set("Access-Control-Allow-Origin", "*")
|
||||
} else if(isAllowedHost(c.Cors.AllowedHosts, requestOrigin)) {
|
||||
} else if isAllowedHost(c.Cors.AllowedHosts, requestOrigin) {
|
||||
headers.Set("Access-Control-Allow-Origin", requestOrigin)
|
||||
headers.Set("Access-Control-Allow-Headers", "*")
|
||||
headers.Set("Access-Control-Allow-Methods", "*")
|
||||
|
||||
Reference in New Issue
Block a user