|
diff --git a/main.go b/main.go index 16c5ca6..d9b2516 100755 --- a/ main.go+++ b/ main.go |
@@ -34,29 +34,35 @@ var params struct { |
34 | |
34 | |
35 | func defaultHandler(w http.ResponseWriter, r *http.Request) { |
35 | func defaultHandler(w http.ResponseWriter, r *http.Request) { |
36 | host := strings.Split(r.Host, ":") |
36 | host := strings.Split(r.Host, ":") |
37 | |
37 | |
38 | if host[0] == "" { |
38 | if host[0] == "" { |
39 | log.Println("Undefined host") |
39 | log.Println("Undefined host") |
40 | http.NotFound(w, r) |
40 | http.NotFound(w, r) |
41 | return |
41 | return |
42 | } |
42 | } |
43 | |
43 | |
44 | request := r.URL.Path[1:] |
44 | request := r.URL.Path[1:] |
45 | requestedFile := params.dir + "/" + host[0] + "/" + request |
45 | requestedFile := params.dir + "/" + host[0] + "/" + request |
46 | log.Println(requestedFile) |
46 | log.Println(requestedFile) |
47 | |
47 | |
48 | file, err := os.Stat(requestedFile) |
48 | file, err := os.Stat(requestedFile) |
49 | if err != nil { |
49 | if err != nil { |
50 | log.Println(err) |
50 | log.Println(err) |
51 | http.NotFound(w, r) |
51 | if os.IsNotExist(err) { |
| |
52 | http.NotFound(w, r) |
| |
53 | } else if os.IsPermission(err) { |
| |
54 | http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden) |
| |
55 | } else { |
| |
56 | http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) |
| |
57 | } |
52 | return |
58 | return |
53 | } |
59 | } |
54 | |
60 | |
55 | if file.IsDir() && !strings.HasSuffix(requestedFile, "/") { |
61 | if file.IsDir() && !strings.HasSuffix(requestedFile, "/") { |
56 | http.Redirect(w, r, r.URL.Path+"/", http.StatusFound) |
62 | http.Redirect(w, r, r.URL.Path+"/", http.StatusFound) |
57 | return |
63 | return |
58 | } |
64 | } |
59 | |
65 | |
60 | http.ServeFile(w, r, requestedFile) |
66 | http.ServeFile(w, r, requestedFile) |
61 | } |
67 | } |
62 | |
68 | |
|