migrated to go

This commit is contained in:
Acid
2026-05-13 19:45:26 -04:00
parent 01a74655e5
commit 7f65419a74
21 changed files with 59 additions and 795 deletions
+42
View File
@@ -0,0 +1,42 @@
package main
import (
"fmt"
"net/http"
"os"
"text/template"
)
func main() {
mux := http.NewServeMux()
// routes
mux.HandleFunc("/", handleRoot)
mux.HandleFunc("/robots.txt", serveRobots)
mux.HandleFunc("/*", handleRoot)
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
fmt.Println("listening on 8080")
http.ListenAndServe(":8080", mux)
}
func handleRoot(w http.ResponseWriter, r *http.Request) {
templ, err := template.ParseFiles("templates/home.html")
if err != nil {
http.Error(w, "template not found", http.StatusInternalServerError)
return
}
templ.Execute(w, nil)
}
func serveRobots(w http.ResponseWriter, r *http.Request) {
robots, err := os.ReadFile("templates/robots.txt")
if err != nil {
fmt.Fprintf(w, "sucks to suck")
return
}
fmt.Fprint(w, string(robots))
}