package router import ( "encoding/json" "os" "path/filepath" "runtime" "strings" "github.com/gofiber/fiber/v3" "goimgApi/accounts" "goimgApi/images" ) func SetupRoutes(app *fiber.App) { app.Get("/", func(c fiber.Ctx) error { return c.SendString("Go Image API Running") }) app.Get("/uploads/*", func(c fiber.Ctx) error { relPath := strings.TrimPrefix(c.Params("*"), "/") if relPath == "" { return fiber.ErrNotFound } cleanPath := filepath.Clean(relPath) if cleanPath == "." || strings.HasPrefix(cleanPath, "..") { return fiber.ErrForbidden } return c.SendFile(filepath.Join("uploads", cleanPath)) }) // Swagger setup app.Get("/docs/swagger.json", func(c fiber.Ctx) error { raw, err := loadSwaggerSpec() if err != nil { return fiber.NewError(fiber.StatusInternalServerError, "Swagger spec could not be loaded") } var spec map[string]any if err := json.Unmarshal(raw, &spec); err != nil { return fiber.NewError(fiber.StatusInternalServerError, "Swagger spec is invalid") } delete(spec, "host") delete(spec, "schemes") return c.JSON(spec) }) app.Get("/swagger", func(c fiber.Ctx) error { c.Set("Content-Type", "text/html") return c.SendString(`