package main import ( "embed" "github.com/gorilla/mux" "html/template" "log" "net/http" "os" ) //go:embed *.json *.css *.js *.svg var content embed.FS //go:embed *.tmpl var internal embed.FS var templates *template.Template func main() { port := os.Getenv("DERELICTPORT") if port == "" { port = "8080" } templates = template.Must(template.ParseFS(internal, "*.tmpl")) router := mux.NewRouter() router.HandleFunc("/", handleRecent).Methods("GET") router.HandleFunc("/view", handleView).Queries("id", "{id:[_0-9]+}").Methods("GET") router.PathPrefix("/").Handler(http.FileServer(http.FS(content))) log.Fatal(http.ListenAndServe(":"+port, router)) } func handleRecent(w http.ResponseWriter, r *http.Request) { templates.ExecuteTemplate(w, "recent", "") } func handleView(w http.ResponseWriter, r *http.Request) { templates.ExecuteTemplate(w, "view", "") }