Codevault initial commit

This commit is contained in:
2026-08-16 16:23:14 +03:00
commit 6ee80f1c8f
47 changed files with 3177 additions and 0 deletions

35
internal/api/swagger.go Normal file
View File

@@ -0,0 +1,35 @@
package api
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// RegisterSwaggerHandlers serves the OpenAPI spec and an interactive Swagger UI
// (embedded swagger-ui-dist assets, no CDN) under /api.
func RegisterSwaggerHandlers(router *gin.Engine) error {
spec, err := GetSwagger()
if err != nil {
return fmt.Errorf("error on building swagger specification: %w", err)
}
specBody, err := spec.MarshalJSON()
if err != nil {
return fmt.Errorf("error on marshaling swagger specification: %w", err)
}
// /api/docs/*any (rather than /api/*any) so this wildcard doesn't collide with
// the static /api/openapi.json route at the same tree level.
router.GET("/api/openapi.json", func(c *gin.Context) {
c.Data(http.StatusOK, "application/json", specBody)
})
router.GET("/api", func(c *gin.Context) {
c.Redirect(http.StatusFound, "/api/docs/index.html")
})
router.GET("/api/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, ginSwagger.URL("/api/openapi.json")))
return nil
}