add swagger

This commit is contained in:
2025-12-20 17:36:24 +02:00
parent 78a8e46b3e
commit f0d7d79e0f
4 changed files with 2520 additions and 1 deletions

View File

@@ -11,12 +11,14 @@ import (
api_acladmin "git.oblat.lv/alex/triggerssmith/api/acl_admin"
api_auth "git.oblat.lv/alex/triggerssmith/api/auth"
api_block "git.oblat.lv/alex/triggerssmith/api/block"
_ "git.oblat.lv/alex/triggerssmith/docs"
"git.oblat.lv/alex/triggerssmith/internal/acl"
"git.oblat.lv/alex/triggerssmith/internal/auth"
"git.oblat.lv/alex/triggerssmith/internal/config"
"git.oblat.lv/alex/triggerssmith/internal/vars"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
httpSwagger "github.com/swaggo/http-swagger"
)
type Router struct {
@@ -66,7 +68,7 @@ func (r *Router) MustRoute() chi.Router {
slog.String("dir", r.cfg.Server.StaticConfig.Dir),
slog.String("index_file", r.cfg.Server.StaticConfig.IndexFile),
)
r.r.Get("/", func(w http.ResponseWriter, req *http.Request) {
r.r.Get("/*", func(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, filepath.Join(r.cfg.Server.StaticConfig.Dir, r.cfg.Server.StaticConfig.IndexFile))
})
fs := http.FileServer(http.Dir(r.cfg.Server.StaticConfig.Dir))
@@ -82,6 +84,9 @@ func (r *Router) MustRoute() chi.Router {
}
r.r.Route("/api", func(api chi.Router) {
api.Get("/swagger/*", httpSwagger.Handler(
httpSwagger.URL("/api/swagger/doc.json"),
))
api.Route("/block", api_block.MustRoute(r.cfg))
authRoute := api_auth.MustRoute(r.cfg, r.authService)
api.Route("/auth", authRoute)