From bc91175e1cbe77ba84d511d0560d36ff745d0b9a Mon Sep 17 00:00:00 2001 From: raul Date: Tue, 30 Apr 2024 10:53:18 +0200 Subject: [PATCH] Add starting files --- go.mod | 3 +++ index.html | 17 +++++++++++++++++ main.go | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 go.mod create mode 100644 index.html create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0bf93cf --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module uploader + +go 1.22.2 diff --git a/index.html b/index.html new file mode 100644 index 0000000..5cc1d26 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + +

Test

+ + + +
+ +
+ + + + diff --git a/main.go b/main.go new file mode 100644 index 0000000..338d7f8 --- /dev/null +++ b/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "io" + "log" + "net/http" + "os" +) + +func getRoot(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Received connection\n") + file, err := os.Open("./index.html") + if err != nil { + log.Printf("Error happened opening index.html: %v\n", err) + } + defer file.Close() + data, err := io.ReadAll(file) + if err != nil { + log.Printf("Error happened reading data: %v\n", err) + } + fmt.Fprint(w, string(data)) +} + +func uploadFile(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Received upload!\n") + fmt.Println(w, "You have uploaded something") +} + +func main() { + http.HandleFunc("/", getRoot) + http.HandleFunc("/api/upload", uploadFile) + + err := http.ListenAndServe(":8080", nil) + if err != nil { + log.Fatal(err) + } +}