whatcanGOwrong

This commit is contained in:
2024-09-19 21:38:24 -04:00
commit d0ae4d841d
17908 changed files with 4096831 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"fmt"
"net/http"
"os"
"time"
)
// 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)
return
}
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)
}
// Serve the current time as plain text
func serveTime(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, time.Now().Format(time.RFC1123))
}
func main() {
// Serve the HTML file on the root URL
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
// Serve the current time on the /time endpoint
http.HandleFunc("/time", serveTime)
// Start the server on port 8085
http.ListenAndServe(":8085", nil)
}