Migrate to a better architectured project
This commit is contained in:
parent
cc5ed5f23e
commit
b1b9eaa028
21 changed files with 2712 additions and 1540 deletions
64
internal/api/router.go
Normal file
64
internal/api/router.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
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/models"
|
||||
)
|
||||
|
||||
// SetupRouter creates and configures the Gin router
|
||||
func SetupRouter(status *models.SystemStatus, 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", handlers.GetDevices)
|
||||
|
||||
// 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue