-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug on uploading file on private folder
- Loading branch information
Showing
3 changed files
with
38 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,44 @@ | ||
package routers | ||
|
||
import "fmt" | ||
import "net/http" | ||
import "SimpleHTTPServer-golang/src/controllers" | ||
import ( | ||
"SimpleHTTPServer-golang/src/controllers" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
// Routing function | ||
func Router(w http.ResponseWriter, req *http.Request) { | ||
fmt.Printf("\"%s %s %s %s\" \"%s\" \"%s\"\n", | ||
req.RemoteAddr, | ||
req.Method, | ||
req.URL.String(), | ||
req.Proto, | ||
req.Referer(), | ||
req.UserAgent()) // TODO: Improve this crappy logging | ||
switch req.Method { | ||
case "GET": | ||
//controllers.HandleFile(w, req) | ||
//controllers.ParseHttpParameter(w, req) | ||
ParseHttpParameter(w, req) | ||
fmt.Printf("\"%s %s %s %s\" \"%s\" \"%s\"\n", | ||
req.RemoteAddr, | ||
req.Method, | ||
req.URL.String(), | ||
req.Proto, | ||
req.Referer(), | ||
req.UserAgent()) // TODO: Improve this crappy logging | ||
switch req.Method { | ||
case "GET": | ||
//controllers.HandleFile(w, req) | ||
//controllers.ParseHttpParameter(w, req) | ||
ParseHttpParameter(w, req) | ||
|
||
case "POST": | ||
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form. | ||
if err := req.ParseForm(); err != nil { | ||
fmt.Fprintf(w, "ParseForm() err: %v", err) | ||
return | ||
} | ||
controllers.UploadFile(w,req) | ||
case "POST": | ||
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form. | ||
if err := req.ParseForm(); err != nil { | ||
fmt.Fprintf(w, "ParseForm() err: %v", err) | ||
return | ||
} | ||
controllers.UploadFile(w, req) | ||
|
||
default: | ||
fmt.Fprintf(w, "Sorry, only GET and POST methods are supported.") | ||
} | ||
default: | ||
fmt.Fprintf(w, "Sorry, only GET and POST methods are supported.") | ||
} | ||
} | ||
|
||
// See https://gist.github.com/elithrar/7600878#comment-955958 for how to extend it to suit simple http.Handler's | ||
func Use(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc { | ||
for _, m := range middleware { | ||
h = m(h) | ||
|
||
} | ||
return h | ||
} |