package main import ( "html/template" "log" "net/http" ) // Configuration holds all website configuration type Config struct { CompanyName string KVK string Email string Phone string Port string } // PageData holds data for template rendering type PageData struct { CompanyName string Title string KVK string Email string Phone string } // Server holds the application state type Server struct { config Config templates *template.Template } // NewServer creates a new server instance func NewServer() *Server { // Configuration - replace these with your actual values config := Config{ CompanyName: "Hogeland Linux", KVK: "12345678", // Replace with actual KVK number Email: "info@hogelandlinux.nl", Phone: "+31 6 12345678", Port: ":8080", } // Parse templates with error handling templates, err := template.ParseGlob("templates/*.html") if err != nil { log.Fatalf("Failed to parse templates: %v", err) } return &Server{ config: config, templates: templates, } } // createPageData creates PageData with the given title func (s *Server) createPageData(title string) PageData { return PageData{ CompanyName: s.config.CompanyName, Title: title, KVK: s.config.KVK, Email: s.config.Email, Phone: s.config.Phone, } } // renderTemplate renders a template with error handling func (s *Server) renderTemplate(w http.ResponseWriter, templateName string, data PageData) { if err := s.templates.ExecuteTemplate(w, templateName, data); err != nil { log.Printf("Template execution error: %v", err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) } } // homeHandler handles the home page func (s *Server) homeHandler(w http.ResponseWriter, r *http.Request) { data := s.createPageData("Linux Migratie Service - Uw Computer Nieuw Leven Geven") s.renderTemplate(w, "index.html", data) } // contactHandler handles the contact page func (s *Server) contactHandler(w http.ResponseWriter, r *http.Request) { data := s.createPageData("Contact - " + s.config.CompanyName) s.renderTemplate(w, "contact.html", data) } // setupRoutes configures all HTTP routes func (s *Server) setupRoutes() { // Static files fs := http.FileServer(http.Dir("static/")) http.Handle("/static/", http.StripPrefix("/static/", fs)) // Page routes http.HandleFunc("/", s.homeHandler) http.HandleFunc("/contact", s.contactHandler) } func main() { server := NewServer() server.setupRoutes() log.Printf("Server starting on %s", server.config.Port) log.Fatal(http.ListenAndServe(server.config.Port, nil)) }