17ca1f6e6c
Implement all HTTP handlers using Go 1.22+ stdlib ServeMux with
HTMX fragment vs full-page response detection.
- internal/handlers/handlers.go: all route handlers
- GET /health returns 200 for K8s probes
- GET / dashboard with triage queue from aggregation layer
- GET /issues lists all issues across orgs
- GET /pulls lists all PRs across orgs
- POST /issues creates issue via aggregation layer
- POST /issues/{owner}/{repo}/{index}/labels assigns labels
- POST /pulls/{owner}/{repo}/{index}/review submits PR review
- HX-Request header detection for HTMX fragment vs full page
- Mobile-first dark theme base layout with bottom navigation
- cmd/server/main.go: refactored to use centralized route registration
- internal/handlers/handlers_test.go: unit tests for health, dashboard,
HTMX detection, input validation
Closes leeworks-agents/gitea-mobile#4
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
|
|
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/config"
|
|
giteaclient "gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/gitea"
|
|
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/handlers"
|
|
"gitea.leeworks.dev/0xwheatyz/gitea-mobile/internal/middleware"
|
|
)
|
|
|
|
func main() {
|
|
// Set up structured logging.
|
|
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
|
Level: slog.LevelInfo,
|
|
})))
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
log.Fatalf("configuration error: %v", err)
|
|
}
|
|
|
|
// Create Gitea API client.
|
|
client := giteaclient.NewClient(cfg.GiteaURL)
|
|
|
|
// Create handler with all routes.
|
|
mux := http.NewServeMux()
|
|
h := handlers.NewHandler(cfg, client)
|
|
h.RegisterRoutes(mux)
|
|
|
|
// Apply middleware chain: logging -> auth.
|
|
var handler http.Handler = mux
|
|
handler = middleware.Auth(cfg.SessionSecret)(handler)
|
|
handler = middleware.Logging()(handler)
|
|
|
|
slog.Info("server starting", "addr", cfg.ListenAddr, "gitea_url", cfg.GiteaURL)
|
|
if err := http.ListenAndServe(cfg.ListenAddr, handler); err != nil {
|
|
log.Fatalf("server error: %v", err)
|
|
}
|
|
}
|