-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (31 loc) · 821 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"html/template"
"net/http"
)
type PageData struct {
Title string
Message string
}
func main() {
// Serve static files (e.g., CSS, JS, images)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
// Define a handler for the home page
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := PageData{
Title: "Welcome to My Go App",
Message: "This is a simple web interface using Go.",
}
tmpl, err := template.ParseFiles("templates/index.html")
if err != nil {
http.Error(w, "Error loading template", http.StatusInternalServerError)
return
}
tmpl.Execute(w, data)
})
// Start the server
port := "8080"
fmt.Printf("Starting server on port %s...\n", port)
http.ListenAndServe(":"+port, nil)
}