summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorhorus_arch2015-05-12 20:57:04 +0200
committerhorus_arch2015-05-12 20:57:04 +0200
commit2e8e63e4a719a2b3adeeed2f1f54a8f3388ac2e4 (patch)
tree2ca8ba44cab2a662cccee50f0a8a616dde119027 /main.go
parent5986015358e5b7cf523122bbdb6831dccf7ca306 (diff)
downloaduhttpd-2e8e63e4a719a2b3adeeed2f1f54a8f3388ac2e4.tar.gz
Add upload form.
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 0 insertions, 45 deletions
diff --git a/main.go b/main.go
index 452ed35..c17edd1 100644
--- a/main.go
+++ b/main.go
@@ -3,11 +3,9 @@ package main
import (
"flag"
"fmt"
- "io"
"log"
"net/http"
"os"
- "strings"
)
func accessLog(h http.Handler, quiet bool) http.Handler {
@@ -21,49 +19,6 @@ func accessLog(h http.Handler, quiet bool) http.Handler {
return http.HandlerFunc(fn)
}
-func uploadHandler(dir string, quiet bool) http.Handler {
- fn := func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Server", "uhttpd")
- file, header, err := r.FormFile("file")
-
- if err != nil {
- w.WriteHeader(500)
- w.Write([]byte(err.Error()))
- log.Println("ERROR", err.Error())
- return
- }
-
- defer file.Close()
-
- if !strings.HasSuffix(dir, "/") {
- dir = dir + "/"
- }
-
- out, err := os.Create(dir + header.Filename)
- if err != nil {
- w.WriteHeader(500)
- w.Write([]byte(err.Error()))
- log.Println("ERROR", err.Error())
- return
- }
-
- defer out.Close()
- _, err = io.Copy(out, file)
- if err != nil {
- w.WriteHeader(500)
- w.Write([]byte(err.Error()))
- log.Println("ERROR", err.Error())
- return
- }
-
- if !quiet {
- log.Println(r.Method, r.URL.Path, header.Filename, r.RemoteAddr)
- }
- w.Write([]byte("Uploaded " + header.Filename))
- }
- return http.HandlerFunc(fn)
-}
-
func main() {
ip_f := flag.String("ip", "0.0.0.0", "IP adress to listen on.")
port_f := flag.String("port", "3000", "Port to listen on.")