plakken/main.go

40 lines
737 B
Go
Raw Normal View History

package main
import (
2023-10-02 20:33:13 +02:00
"fmt"
"net/http"
"strings"
)
var currentConfig config
func handleRequest(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
2023-10-02 20:33:13 +02:00
switch r.Method {
case "GET":
if path == "/" {
http.ServeFile(w, r, "./static/index.html")
2023-10-02 20:33:13 +02:00
} else if strings.HasPrefix(path, "/static/") {
fs := http.FileServer(http.Dir("./static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
} else {
w.WriteHeader(http.StatusNotFound)
}
case "POST":
fmt.Println("Post!")
}
}
func main() {
currentConfig = setConfig()
2023-10-02 15:03:04 +02:00
listen := currentConfig.host + ":" + currentConfig.port
http.HandleFunc("/", handleRequest)
2023-10-02 15:03:04 +02:00
err := http.ListenAndServe(listen, nil)
if err != nil {
2023-10-02 20:33:13 +02:00
fmt.Println(err)
}
}