Files
mtusi2026lab2_fork/backend/internal/httpapi/router.go
T

46 lines
1023 B
Go

package httpapi
import (
"github.com/gin-gonic/gin"
"high-loud-apps-labs/internal/httpapi/handler"
"high-loud-apps-labs/internal/httpapi/middleware"
)
type Handlers struct {
Health *handler.HealthHandler
User *handler.UserHandler
Chat *handler.ChatHandler
Message *handler.MessageHandler
}
func NewRouter(h Handlers, auth gin.HandlerFunc) *gin.Engine {
gin.EnableJsonDecoderDisallowUnknownFields()
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.RequestID())
r.GET("/health/live", h.Health.Live)
r.GET("/health/ready", h.Health.Ready)
api := r.Group("/api/v1")
{
api.POST("/users", h.User.Create)
}
protected := api.Group("")
protected.Use(auth)
{
protected.GET("/users/me", h.User.Current)
protected.POST("/chats", h.Chat.Create)
protected.GET("/chats", h.Chat.List)
protected.GET("/chats/:chat_id", h.Chat.Get)
protected.POST("/chats/:chat_id/messages", h.Message.Create)
protected.GET("/chats/:chat_id/messages", h.Message.List)
}
return r
}