routewatch/internal/templates/templates.go
sneak 585ff63fae Remove BGP keepalive logging and add peer tracking
- Created bgp_peers table to track all BGP peers
- Added PeerHandler to update peer last seen times for all message types
- Removed verbose BGP keepalive debug logging
- BGP keepalive messages now silently update peer tracking

Refactor HTML templates to use go:embed

- Created internal/templates package with embedded templates
- Moved status.html from inline const to separate file
- Templates are parsed once on startup
- Server now uses parsed template instead of raw string

Optimize AS data embedding with gzip compression

- Changed asinfo package to embed gzipped data (2.4MB vs 12MB)
- Updated Makefile to gzip AS data during update
- Added decompression during initialization
- Raw JSON file excluded from git
2025-07-27 21:54:58 +02:00

49 lines
1018 B
Go

// Package templates provides embedded HTML templates for the RouteWatch application
package templates
import (
_ "embed"
"html/template"
"sync"
)
//go:embed status.html
var statusHTML string
// Templates contains all parsed templates
type Templates struct {
Status *template.Template
}
var (
//nolint:gochecknoglobals // Singleton pattern for templates
defaultTemplates *Templates
//nolint:gochecknoglobals // Singleton pattern for templates
once sync.Once
)
// initTemplates parses all embedded templates
func initTemplates() {
var err error
defaultTemplates = &Templates{}
// Parse status template
defaultTemplates.Status, err = template.New("status").Parse(statusHTML)
if err != nil {
panic("failed to parse status template: " + err.Error())
}
}
// Get returns the singleton Templates instance
func Get() *Templates {
once.Do(initTemplates)
return defaultTemplates
}
// StatusTemplate returns the parsed status template
func StatusTemplate() *template.Template {
return Get().Status
}