feat: add API versioning , translate swagger, remove rate limiter
ci / build (push) Successful in 2m42s
ci / build (pull_request) Successful in 2m45s

This commit is contained in:
Mephimeow
2026-06-14 17:14:37 +00:00
parent 2da484d781
commit ff355ad1d9
7 changed files with 417 additions and 409 deletions
+10 -9
View File
@@ -12,7 +12,6 @@ import (
docs "gitea.d3m0k1d.ru/HellreigN/Control-plane/docs"
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/auth"
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/config"
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/middleware"
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/org"
"github.com/gin-gonic/gin"
"github.com/pressly/goose/v3"
@@ -24,13 +23,16 @@ import (
// @title AegisGuard API
// @version 1.0
// @description API для AegisGuard control plane
// @description API системы управления AegisGuard. Позволяет управлять пользователями и организациями.
// @description Все защищённые эндпоинты требуют заголовок `Authorization: Bearer <token>`.
// @description Токен получается при регистрации или входе.
// @schemes http
// @BasePath /api/v1
//
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @description Type "Bearer" followed by a space and the JWT token.
// @description Введите `Bearer <token>`, где token — access_token из ответа /auth/login или /auth/register
func main() {
cfg, err := config.Load()
@@ -70,7 +72,6 @@ func main() {
orgSvc := org.NewService(orgRepo)
orgHandler := org.NewHandler(orgSvc)
loginLimiter := middleware.NewRateLimiter(10, time.Minute)
authMW := auth.AuthMiddleware([]byte(cfg.JWTSecret))
go func() {
@@ -91,17 +92,18 @@ func main() {
docs.SwaggerInfo.Title = "AegisGuard API"
docs.SwaggerInfo.Version = "1.0"
docs.SwaggerInfo.Description = "API for AegisGuard"
docs.SwaggerInfo.Description = "API системы управления AegisGuard. Позволяет управлять пользователями и организациями."
docs.SwaggerInfo.Schemes = []string{"http"}
docs.SwaggerInfo.BasePath = "/api/v1"
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
r.GET("/health", func(c *gin.Context) {
c.JSON(200, gin.H{"status": "ok"})
})
api := r.Group("/api/auth")
api := r.Group("/api/v1/auth")
{
api.POST("/register", handler.Register)
api.POST("/login", loginLimiter.Middleware(), handler.Login)
api.POST("/login", handler.Login)
api.POST("/refresh", handler.Refresh)
api.POST("/logout", handler.Logout)
api.GET("/me", authMW, handler.Me)
@@ -109,7 +111,7 @@ func main() {
api.PUT("/password", authMW, handler.ChangePassword)
}
orgs := r.Group("/api/organizations", authMW)
orgs := r.Group("/api/v1/organizations", authMW)
{
orgs.POST("", orgHandler.Create)
orgs.GET("", orgHandler.List)
@@ -144,7 +146,6 @@ func main() {
log.Fatalf("server forced to shutdown: %v", err)
}
loginLimiter.Stop()
_ = sqlDB.Close()
log.Println("server stopped")