diff --git a/main.go b/main.go index b34fff2..a65617b 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,16 @@ import ( "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 @@ -14,46 +24,81 @@ type PageData struct { Phone string } -func main() { - // Parse templates - tmpl := template.Must(template.ParseGlob("templates/*.html")) +// 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)) - // Home page - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - data := PageData{ - CompanyName: "Hogeland Linux", - Title: "Linux Migratie Service - Uw Computer Nieuw Leven Geven", - KVK: "12345678", // Replace with actual KVK number - Email: "info@hogelandlinux.nl", - Phone: "+31 6 12345678", - } - - if err := tmpl.ExecuteTemplate(w, "index.html", data); err != nil { - log.Printf("Template execution error: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - } - }) - - // Contact page - http.HandleFunc("/contact", func(w http.ResponseWriter, r *http.Request) { - data := PageData{ - CompanyName: "Hogeland Linux", - Title: "Contact - Hogeland Linux", - KVK: "12345678", // Replace with actual KVK number - Email: "info@hogelandlinux.nl", - Phone: "+31 6 12345678", - } - - if err := tmpl.ExecuteTemplate(w, "contact.html", data); err != nil { - log.Printf("Template execution error: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - } - }) - - log.Println("Server starting on :8080") - log.Fatal(http.ListenAndServe(":8080", nil)) + // 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)) } diff --git a/templates/index.html b/templates/index.html index daf7d96..e37a9ae 100644 --- a/templates/index.html +++ b/templates/index.html @@ -179,8 +179,8 @@

Ziet er vertrouwd uit voor Windows gebruikers. Stabiel en betrouwbaar.

- ✓ Vertrouwd interface - ✓ Multimedia support + ✓ Vertrouwde interface + ✓ Multimedia ondersteuning ✓ Zeer stabiel

Ideaal voor: Windows migratie, ouderen, conservatieve gebruikers

@@ -192,13 +192,13 @@

Pop!_OS

Gaming -

Gemaakt door System76. Excellent voor gaming en creatief werk.

+

Gemaakt door System76. Uitstekend voor gaming en creatief werk.

- ✓ Gaming optimized - ✓ NVIDIA support - ✓ Modern design + ✓ Gaming-geoptimaliseerd + ✓ NVIDIA ondersteuning + ✓ Modern ontwerp
-

Ideaal voor: Gamers, developers, jongeren

+

Ideaal voor: Gamers, ontwikkelaars, jongeren

@@ -207,10 +207,10 @@

Elementary OS

Mooi
-

Prachtig design geïnspireerd door macOS. Eenvoudig en elegant.

+

Prachtig ontwerp geïnspireerd door macOS. Eenvoudig en elegant.

- ✓ Elegant design - ✓ Privacy-focused + ✓ Elegant ontwerp + ✓ Privacy-gericht ✓ Mac-achtig

Ideaal voor: Mac gebruikers, designers, stijlbewuste mensen

@@ -222,28 +222,28 @@

Fedora

Geavanceerd -

Nieuwste technologieën en features. Voor technische gebruikers.

+

Nieuwste technologieën en functies. Voor technische gebruikers.

- ✓ Cutting-edge + ✓ Geavanceerde technologie ✓ Red Hat basis - ✓ Developer tools + ✓ Ontwikkelaarstools
-

Ideaal voor: Developers, IT professionals, tech enthusiasts

+

Ideaal voor: Ontwikkelaars, IT professionals, tech-enthousiasten

Garuda Linux

- Performance + Prestaties
-

Arch-based met extreme prestaties. Prachtig design en gaming-geoptimaliseerd.

+

Arch-gebaseerd met extreme prestaties. Prachtig ontwerp en gaming-geoptimaliseerd.

✓ Arch basis - ✓ Gaming ready - ✓ Beautiful UI + ✓ Gaming-klaar + ✓ Mooie interface
-

Ideaal voor: Power users, gamers, performance enthusiasts

+

Ideaal voor: Powergebruikers, gamers, prestatie-enthousiasten