Skip to content

Commit 96b098f

Browse files
committed
feat(resolvespec): accept bunrouter.Router and bunrouter.Group in SetupBunRouterRoutes
Replaced *router.StandardBunRouterAdapter parameter with BunRouterHandler interface to support both bunrouter.Router and bunrouter.Group types, enabling route registration on router groups with path prefixes. - Added BunRouterHandler interface - Updated SetupBunRouterRoutes signature - Updated example functions to use bunrouter.New() directly - Added ExampleBunRouterWithGroup demonstrating group usage
1 parent 5bba99e commit 96b098f

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

pkg/resolvespec/resolvespec.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,14 @@ func ExampleWithBun(bunDB *bun.DB) {
207207
SetupMuxRoutes(muxRouter, handler, nil)
208208
}
209209

210+
// BunRouterHandler is an interface that both bunrouter.Router and bunrouter.Group implement
211+
type BunRouterHandler interface {
212+
Handle(method, path string, handler bunrouter.HandlerFunc)
213+
}
214+
210215
// SetupBunRouterRoutes sets up bunrouter routes for the ResolveSpec API
211-
func SetupBunRouterRoutes(bunRouter *router.StandardBunRouterAdapter, handler *Handler) {
212-
r := bunRouter.GetBunRouter()
216+
// Accepts bunrouter.Router or bunrouter.Group
217+
func SetupBunRouterRoutes(r BunRouterHandler, handler *Handler) {
213218

214219
// CORS config
215220
corsConfig := common.DefaultCORSConfig()
@@ -337,13 +342,13 @@ func ExampleWithBunRouter(bunDB *bun.DB) {
337342
handler := NewHandlerWithBun(bunDB)
338343

339344
// Create bunrouter
340-
bunRouter := router.NewStandardBunRouterAdapter()
345+
bunRouter := bunrouter.New()
341346

342347
// Setup ResolveSpec routes with bunrouter
343348
SetupBunRouterRoutes(bunRouter, handler)
344349

345350
// Start server
346-
// http.ListenAndServe(":8080", bunRouter.GetBunRouter())
351+
// http.ListenAndServe(":8080", bunRouter)
347352
}
348353

349354
// ExampleBunRouterWithBunDB shows the full uptrace stack (bunrouter + Bun ORM)
@@ -359,11 +364,29 @@ func ExampleBunRouterWithBunDB(bunDB *bun.DB) {
359364
handler := NewHandler(dbAdapter, registry)
360365

361366
// Create bunrouter
362-
bunRouter := router.NewStandardBunRouterAdapter()
367+
bunRouter := bunrouter.New()
363368

364369
// Setup ResolveSpec routes
365370
SetupBunRouterRoutes(bunRouter, handler)
366371

367372
// This gives you the full uptrace stack: bunrouter + Bun ORM
368-
// http.ListenAndServe(":8080", bunRouter.GetBunRouter())
373+
// http.ListenAndServe(":8080", bunRouter)
374+
}
375+
376+
// ExampleBunRouterWithGroup shows how to use SetupBunRouterRoutes with a bunrouter.Group
377+
func ExampleBunRouterWithGroup(bunDB *bun.DB) {
378+
// Create handler with Bun adapter
379+
handler := NewHandlerWithBun(bunDB)
380+
381+
// Create bunrouter
382+
bunRouter := bunrouter.New()
383+
384+
// Create a route group with a prefix
385+
apiGroup := bunRouter.NewGroup("/api")
386+
387+
// Setup ResolveSpec routes on the group - routes will be under /api
388+
SetupBunRouterRoutes(apiGroup, handler)
389+
390+
// Start server
391+
// http.ListenAndServe(":8080", bunRouter)
369392
}

0 commit comments

Comments
 (0)