diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-07-29 19:05:54 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-07-29 19:05:57 -0400 |
commit | 72d420e8acc77c8649d36c0ce92ae51749ecd6c5 (patch) | |
tree | badfafb52d1cf45f19420c39186190b58d27ba74 | |
parent | 4619d665d8fc347ff523699ca8c71ec9fadb5326 (diff) |
Serve a basic html page and REST api endpoint
-rw-r--r-- | main.go | 20 | ||||
-rw-r--r-- | static/index.html | 8 |
2 files changed, 27 insertions, 1 deletions
@@ -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) + } } diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..0e5ea7b --- /dev/null +++ b/static/index.html @@ -0,0 +1,8 @@ +<html> + <head> + <title>This is a good page!</title> + </head> + <body> + Hello, world! + </body> +</html> |