Code quality improvements and Dutch language fixes
- Refactored Go code for better maintainability: * Eliminated DRY violations with Server struct * Added proper configuration management * Separated concerns with dedicated handlers * Improved error handling - Fixed Dutch grammar and language issues: * Translated all English tech terms to Dutch * Fixed mixed English/Dutch descriptions * Improved naturalness of Dutch phrases * Updated distro tags and feature descriptions
This commit is contained in:
119
main.go
119
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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user