From 72d420e8acc77c8649d36c0ce92ae51749ecd6c5 Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Tue, 29 Jul 2025 19:05:54 -0400 Subject: Serve a basic html page and REST api endpoint --- main.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index f477bbf..fba15c1 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,26 @@ package main import ( "fmt" + "net/http" ) func main() { - fmt.Println("hi") + fs := http.FileServer(http.Dir("static")) + + // Define a handler function for the root path + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + // Serve the index.html file from the static directory + http.StripPrefix("/", fs).ServeHTTP(w, r) + }) + + http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "foo!") + }) + + // Start the server on port 8080 + fmt.Println("Server is listening on port 8080...") + err := http.ListenAndServe(":8080", nil) + if err != nil { + fmt.Printf("Error starting server: %s\n", err) + } } -- cgit