refactor: return pointer to router/route info

This commit is contained in:
Mark Bailey 2025-09-06 18:11:20 -04:00
parent 3891a7874f
commit ff67ba5bf0

View File

@ -20,13 +20,13 @@ type RouteInfo struct {
Title string Title string
} }
func NewRouteInfo(method, path, description, title string) (RouteInfo, error) { func NewRouteInfo(method, path, description, title string) (*RouteInfo, error) {
name, err := convertRouteToRouteName(path) name, err := convertRouteToRouteName(path)
if err != nil { if err != nil {
return RouteInfo{}, err return &RouteInfo{}, err
} }
return RouteInfo{ return &RouteInfo{
Method: method, Method: method,
Name: name, Name: name,
Path: path, Path: path,
@ -43,7 +43,7 @@ type Router struct {
cacheTTL time.Duration cacheTTL time.Duration
} }
func NewRouter() Router { func NewRouter() *Router {
ttl := 8 * time.Hour ttl := 8 * time.Hour
cache, err := NewRouteCacheService(WithTTL(ttl)) cache, err := NewRouteCacheService(WithTTL(ttl))
@ -51,7 +51,7 @@ func NewRouter() Router {
log.Fatal(jerr.Wrap(err, jerr.ErrRouterNotCreated)) log.Fatal(jerr.Wrap(err, jerr.ErrRouterNotCreated))
} }
return Router{cache: cache, cacheTTL: ttl} return &Router{cache: cache, cacheTTL: ttl}
} }
func (ro *Router) WithRouteInfo(ri RouteInfo, h HandlerFn) http.HandlerFunc { func (ro *Router) WithRouteInfo(ri RouteInfo, h HandlerFn) http.HandlerFunc {