repeater/internal/api/router.go
Pierre-Olivier Mercier 2b3a5b89f8 Add configuration system and ARP-based device discovery
Implement comprehensive configuration management with CLI flags for WiFi interface, device discovery method, and file paths. Add ARP table parsing as an alternative to DHCP leases for more reliable device detection. Improve WiFi scanning to handle concurrent scan requests gracefully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-01 23:31:01 +07:00

67 lines
1.5 KiB
Go

package api
import (
"embed"
"io/fs"
"net/http"
"github.com/gin-gonic/gin"
"github.com/nemunaire/repeater/internal/api/handlers"
"github.com/nemunaire/repeater/internal/config"
"github.com/nemunaire/repeater/internal/models"
)
// SetupRouter creates and configures the Gin router
func SetupRouter(status *models.SystemStatus, cfg *config.Config, assets embed.FS) *gin.Engine {
// Set Gin to release mode (can be overridden with GIN_MODE env var)
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
// API routes
api := r.Group("/api")
{
// WiFi endpoints
wifi := api.Group("/wifi")
{
wifi.GET("/scan", handlers.ScanWiFi)
wifi.POST("/connect", handlers.ConnectWiFi)
wifi.POST("/disconnect", handlers.DisconnectWiFi)
}
// Hotspot endpoints
hotspot := api.Group("/hotspot")
{
hotspot.POST("/config", handlers.ConfigureHotspot)
hotspot.POST("/toggle", func(c *gin.Context) {
handlers.ToggleHotspot(c, status)
})
}
// Device endpoints
api.GET("/devices", func(c *gin.Context) {
handlers.GetDevices(c, cfg)
})
// Status endpoint
api.GET("/status", func(c *gin.Context) {
handlers.GetStatus(c, status)
})
// Log endpoints
api.GET("/logs", handlers.GetLogs)
api.DELETE("/logs", handlers.ClearLogs)
}
// WebSocket endpoint
r.GET("/ws/logs", handlers.WebSocketLogs)
// Serve static files
sub, err := fs.Sub(assets, "static")
if err != nil {
panic("Unable to access static directory: " + err.Error())
}
r.NoRoute(gin.WrapH(http.FileServer(http.FS(sub))))
return r
}