Files
gochat/cmd/dump_routes/main.go
T
2026-06-04 15:44:48 +08:00

59 lines
1.1 KiB
Go

package main
import (
"fmt"
"os"
"sort"
"strings"
"github.com/gin-gonic/gin"
"github.com/gochat/gochat/internal/config"
"github.com/gochat/gochat/internal/middleware"
"github.com/gochat/gochat/internal/router"
)
func main() {
gin.SetMode(gin.TestMode)
engine := gin.New()
cfg, err := config.Load()
if err != nil {
fmt.Fprintf(os.Stderr, "config load: %v\n", err)
os.Exit(1)
}
// Create a zero-value Handlers struct — we only need route paths, not working handlers
handlers := &router.Handlers{}
corsCfg := middleware.CORSConfigFromAppConfig(cfg)
router.RegisterRoutes(
engine,
nil, // jwtService
nil, // refreshStore
nil, // webhookRegistry
handlers,
nil, // hub
nil, // wsAuthenticator
&cfg.JWT,
corsCfg,
nil, // db
)
routes := engine.Routes()
sort.Slice(routes, func(i, j int) bool {
if routes[i].Method != routes[j].Method {
return routes[i].Method < routes[j].Method
}
return routes[i].Path < routes[j].Path
})
count := 0
for _, r := range routes {
if strings.HasPrefix(r.Path, "/swagger") {
continue
}
fmt.Printf("%s %s\n", r.Method, r.Path)
count++
}
fmt.Printf("TOTAL: %d\n", count)
}