whatcanGOwrongagain

This commit is contained in:
2024-09-19 21:45:28 -04:00
parent d0ae4d841d
commit 49fc107a14
3 changed files with 50 additions and 67 deletions
+3 -5
View File
@@ -9,7 +9,6 @@ import (
// Serve the index.html file
func serveHTML(w http.ResponseWriter, r *http.Request) {
// Open the file
file, err := os.Open("index.html")
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
@@ -17,7 +16,6 @@ func serveHTML(w http.ResponseWriter, r *http.Request) {
}
defer file.Close()
// Set the content type as HTML and send the file contents
w.Header().Set("Content-Type", "text/html")
http.ServeContent(w, r, "index.html", time.Now(), file)
}
@@ -28,12 +26,12 @@ func serveTime(w http.ResponseWriter, r *http.Request) {
}
func main() {
// Serve the HTML file on the root URL
// Serve the static CSS file from the "static" directory
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Serve the current time on the /time endpoint
http.HandleFunc("/", serveHTML)
http.HandleFunc("/time", serveTime)
// Start the server on port 8085
fmt.Println("Starting server on :8085")
http.ListenAndServe(":8085", nil)
}