All checks were successful
check / check (push) Successful in 56s
DBURL → DATA_DIR consolidation:
- Remove DBURL env var entirely; main DB now lives at {DATA_DIR}/webhooker.db
- database.go constructs DB path from config.DataDir, ensures dir exists
- Update DATA_DIR prod default from /data/events to /data
- Update all tests to use DataDir instead of DBURL
- Update Dockerfile: /data (not /data/events) for all SQLite databases
- Update README configuration table, Docker examples, architecture docs
Dead code removal:
- Remove unused IndexResponse struct (handlers/index.go)
- Remove unused TemplateData struct (handlers/handlers.go)
Stale comment cleanup:
- Remove TODO in server.go (DB cleanup handled by fx lifecycle)
- Fix nolint:golint → nolint:revive on ServerParams for consistency
- Clean up verbose middleware/routing comments in routes.go
- Fix TODO fan-out description (worker pool, not goroutine-per-target)
.gitignore fixes:
- Add data/ directory to gitignore
- Remove stale config.yaml entry (env-only config since rework)
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"sneak.berlin/go/webhooker/internal/database"
|
|
)
|
|
|
|
func (s *Handlers) HandleIndex() http.HandlerFunc {
|
|
// Calculate server start time
|
|
startTime := time.Now()
|
|
|
|
return func(w http.ResponseWriter, req *http.Request) {
|
|
// Calculate uptime
|
|
uptime := time.Since(startTime)
|
|
uptimeStr := formatUptime(uptime)
|
|
|
|
// Get user count from database
|
|
var userCount int64
|
|
s.db.DB().Model(&database.User{}).Count(&userCount)
|
|
|
|
// Prepare template data
|
|
data := map[string]interface{}{
|
|
"Version": s.params.Globals.Version,
|
|
"Uptime": uptimeStr,
|
|
"UserCount": userCount,
|
|
}
|
|
|
|
// Render the template
|
|
s.renderTemplate(w, req, "index.html", data)
|
|
}
|
|
}
|
|
|
|
// formatUptime formats a duration into a human-readable string
|
|
func formatUptime(d time.Duration) string {
|
|
days := int(d.Hours()) / 24
|
|
hours := int(d.Hours()) % 24
|
|
minutes := int(d.Minutes()) % 60
|
|
|
|
if days > 0 {
|
|
return fmt.Sprintf("%dd %dh %dm", days, hours, minutes)
|
|
}
|
|
if hours > 0 {
|
|
return fmt.Sprintf("%dh %dm", hours, minutes)
|
|
}
|
|
return fmt.Sprintf("%dm", minutes)
|
|
}
|