Compare commits

..

4 Commits

Author SHA1 Message Date
96b098f912 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
2026-01-03 16:06:53 +02:00
5bba99efe3 Merge branch 'main' of github.com:bitechdev/ResolveSpec 2026-01-03 14:48:17 +02:00
8504b6d13d fix(staticweb): add nil check to WithStripPrefix helper
Prevent panic when WithStripPrefix is called with a nil provider by
using reflection to check for typed nil pointers stored in interfaces.
2026-01-03 14:47:21 +02:00
ada4db6465 fix(staticweb): add nil check to WithStripPrefix helper
Prevent panic when WithStripPrefix is called with a nil provider.
2026-01-03 14:43:31 +02:00
2 changed files with 34 additions and 7 deletions

View File

@@ -207,9 +207,14 @@ func ExampleWithBun(bunDB *bun.DB) {
SetupMuxRoutes(muxRouter, handler, nil)
}
// BunRouterHandler is an interface that both bunrouter.Router and bunrouter.Group implement
type BunRouterHandler interface {
Handle(method, path string, handler bunrouter.HandlerFunc)
}
// SetupBunRouterRoutes sets up bunrouter routes for the ResolveSpec API
func SetupBunRouterRoutes(bunRouter *router.StandardBunRouterAdapter, handler *Handler) {
r := bunRouter.GetBunRouter()
// Accepts bunrouter.Router or bunrouter.Group
func SetupBunRouterRoutes(r BunRouterHandler, handler *Handler) {
// CORS config
corsConfig := common.DefaultCORSConfig()
@@ -337,13 +342,13 @@ func ExampleWithBunRouter(bunDB *bun.DB) {
handler := NewHandlerWithBun(bunDB)
// Create bunrouter
bunRouter := router.NewStandardBunRouterAdapter()
bunRouter := bunrouter.New()
// Setup ResolveSpec routes with bunrouter
SetupBunRouterRoutes(bunRouter, handler)
// Start server
// http.ListenAndServe(":8080", bunRouter.GetBunRouter())
// http.ListenAndServe(":8080", bunRouter)
}
// ExampleBunRouterWithBunDB shows the full uptrace stack (bunrouter + Bun ORM)
@@ -359,11 +364,29 @@ func ExampleBunRouterWithBunDB(bunDB *bun.DB) {
handler := NewHandler(dbAdapter, registry)
// Create bunrouter
bunRouter := router.NewStandardBunRouterAdapter()
bunRouter := bunrouter.New()
// Setup ResolveSpec routes
SetupBunRouterRoutes(bunRouter, handler)
// This gives you the full uptrace stack: bunrouter + Bun ORM
// http.ListenAndServe(":8080", bunRouter.GetBunRouter())
// http.ListenAndServe(":8080", bunRouter)
}
// ExampleBunRouterWithGroup shows how to use SetupBunRouterRoutes with a bunrouter.Group
func ExampleBunRouterWithGroup(bunDB *bun.DB) {
// Create handler with Bun adapter
handler := NewHandlerWithBun(bunDB)
// Create bunrouter
bunRouter := bunrouter.New()
// Create a route group with a prefix
apiGroup := bunRouter.NewGroup("/api")
// Setup ResolveSpec routes on the group - routes will be under /api
SetupBunRouterRoutes(apiGroup, handler)
// Start server
// http.ListenAndServe(":8080", bunRouter)
}

View File

@@ -3,6 +3,7 @@ package staticweb
import (
"io/fs"
"net/http"
"reflect"
)
// FileSystemProvider abstracts the source of files (local, zip, embedded, future: http, s3)
@@ -51,7 +52,10 @@ type PrefixStrippingProvider interface {
// WithStripPrefix is a helper function that sets the strip prefix on a provider
// if it implements PrefixStrippingProvider. Returns the provider for method chaining.
func WithStripPrefix(provider FileSystemProvider, prefix string) FileSystemProvider {
if p, ok := provider.(PrefixStrippingProvider); ok {
if provider == nil || reflect.ValueOf(provider).IsNil() {
return provider
}
if p, ok := provider.(PrefixStrippingProvider); ok && p != nil {
p.WithStripPrefix(prefix)
}
return provider