Add starting files

This commit is contained in:
raul 2024-04-30 10:53:18 +02:00
parent cc9809f2c2
commit bc91175e1c
3 changed files with 58 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module uploader
go 1.22.2

17
index.html Normal file
View File

@ -0,0 +1,17 @@
<html>
<head>
<link rel="stylesheet" type="" href="./style.css">
<script src="https://unpkg.com/htmx.org@1.9.4/dist/htmx.min.js"></script>
</head>
<body>
<p><b>Test</b></p>
<!-- <form action="/action_page.php"> -->
<!-- <input type="file" id="myFile" name="filename"> -->
<!-- <input type="submit"> -->
<form>
</form>
</form>
</body>
</html>

38
main.go Normal file
View File

@ -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)
}
}