39 lines
746 B
Go
39 lines
746 B
Go
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)
|
|
}
|
|
}
|