diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 20:29:11 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-02-11 20:29:11 +0300 |
commit | 920b15f69cd7749ab5f45b121132e92de2ef6e15 (patch) | |
tree | 1b7fed68042a8a537fe1c8e8a59a3cbdc9176ee6 /domain.go | |
parent | f97ebb63782cb6ac681268651a2234e942b7e90a (diff) |
Reduce code complexity
Diffstat (limited to 'domain.go')
-rw-r--r-- | domain.go | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -40,7 +40,7 @@ func (d *domain) serveFile(w http.ResponseWriter, r *http.Request, fullPath stri return true } -func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) { +func (d *domain) resolvePath(w http.ResponseWriter, r *http.Request, projectName, subPath string) (fullPath string, err error) { publicPath := filepath.Join(*pagesRoot, d.Group, projectName, "public") fullPath = filepath.Join(publicPath, subPath) @@ -53,7 +53,11 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s err = fmt.Errorf("%q should be in %q", fullPath, publicPath) return } + return +} +func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string) (fullPath string, err error) { + fullPath = path fi, err := os.Lstat(fullPath) if err != nil { return @@ -77,11 +81,15 @@ func (d *domain) fullPath(w http.ResponseWriter, r *http.Request, projectName, s } func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, subPath string) bool { - fullPath, err := d.fullPath(w, r, projectName, subPath) + path, err := d.resolvePath(w, r, projectName, subPath) + if err != nil { + return false + } + path, err = d.checkPath(w, r, path) if err != nil { return false } - return d.serveFile(w, r, fullPath) + return d.serveFile(w, r, path) } func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) { |