| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package router
- import (
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/api/server/shared"
- "github.com/porter-dev/porter/api/types"
- )
- func NewNamespaceScopedRegisterer(children ...*Registerer) *Registerer {
- return &Registerer{
- GetRoutes: GetNamespaceScopedRoutes,
- Children: children,
- }
- }
- func GetNamespaceScopedRoutes(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- children ...*Registerer,
- ) []*Route {
- routes, projPath := getNamespaceRoutes(r, config, basePath, factory)
- if len(children) > 0 {
- r.Route(projPath.RelativePath, func(r chi.Router) {
- for _, child := range children {
- childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
- routes = append(routes, childRoutes...)
- }
- })
- }
- return routes
- }
- func getNamespaceRoutes(
- r chi.Router,
- config *shared.Config,
- basePath *types.Path,
- factory shared.APIEndpointFactory,
- ) ([]*Route, *types.Path) {
- relPath := "/namespaces/{namespace}"
- newPath := &types.Path{
- Parent: basePath,
- RelativePath: relPath,
- }
- routes := make([]*Route, 0)
- return routes, newPath
- }
|