Created
December 1, 2025 17:32
-
-
Save timmatheson/b985f01740d98fa12a44453dc52cc8e3 to your computer and use it in GitHub Desktop.
Simple single page web app using Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| // Define a handler function for the root path "/" | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| // Set the Content-Type header to indicate HTML content | |
| w.Header().Set("Content-Type", "text/html; charset=utf-8") | |
| // Write the HTML content to the response writer | |
| fmt.Fprintf(w, ` | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Simple Go Page</title> | |
| <style> | |
| body { font-family: sans-serif; text-align: center; margin-top: 50px; } | |
| h1 { color: #333; } | |
| p { color: #666; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Welcome to My Simple Go Application!</h1> | |
| <p>This is a single page served by a Go web server.</p> | |
| </body> | |
| </html> | |
| `) | |
| }) | |
| // Start the HTTP server on port 8080 | |
| port := ":8080" | |
| log.Printf("Server starting on port %s\n", port) | |
| err := http.ListenAndServe(port, nil) | |
| if err != nil { | |
| log.Fatalf("Server failed to start: %v", err) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment