mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-11-01 06:35:43 +00:00
refactor: move resource handling to a controller
This commit is contained in:
@@ -14,6 +14,7 @@ func NewHealthController(router *gin.RouterGroup) *HealthController {
|
||||
|
||||
func (controller *HealthController) SetupRoutes() {
|
||||
controller.Router.GET("/health", controller.healthHandler)
|
||||
controller.Router.HEAD("/health", controller.healthHandler)
|
||||
}
|
||||
|
||||
func (controller *HealthController) healthHandler(c *gin.Context) {
|
||||
|
||||
32
internal/controller/resources_controller.go
Normal file
32
internal/controller/resources_controller.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ResourcesControllerConfig struct {
|
||||
ResourcesDir string
|
||||
}
|
||||
|
||||
type ResourcesController struct {
|
||||
Config ResourcesControllerConfig
|
||||
Router *gin.RouterGroup
|
||||
}
|
||||
|
||||
func NewResourcesController(config ResourcesControllerConfig, router *gin.RouterGroup) *ResourcesController {
|
||||
return &ResourcesController{
|
||||
Config: config,
|
||||
Router: router,
|
||||
}
|
||||
}
|
||||
|
||||
func (controller *ResourcesController) SetupRoutes() {
|
||||
controller.Router.GET("/resources/*resource", controller.resourcesHandler)
|
||||
}
|
||||
|
||||
func (controller *ResourcesController) resourcesHandler(c *gin.Context) {
|
||||
fileServer := http.StripPrefix("/resources", http.FileServer(http.Dir(controller.Config.ResourcesDir)))
|
||||
fileServer.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
Reference in New Issue
Block a user