project.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package v1
  2. import (
  3. "github.com/go-chi/chi"
  4. "github.com/porter-dev/porter/api/server/shared"
  5. "github.com/porter-dev/porter/api/server/shared/config"
  6. "github.com/porter-dev/porter/api/server/shared/router"
  7. "github.com/porter-dev/porter/api/types"
  8. )
  9. func NewV1ProjectScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  10. return &router.Registerer{
  11. GetRoutes: GetV1ProjectScopedRoutes,
  12. Children: children,
  13. }
  14. }
  15. func GetV1ProjectScopedRoutes(
  16. r chi.Router,
  17. config *config.Config,
  18. basePath *types.Path,
  19. factory shared.APIEndpointFactory,
  20. children ...*router.Registerer,
  21. ) []*router.Route {
  22. routes, projPath := getV1ProjectRoutes(r, config, basePath, factory)
  23. if len(children) > 0 {
  24. r.Route(projPath.RelativePath, func(r chi.Router) {
  25. for _, child := range children {
  26. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  27. routes = append(routes, childRoutes...)
  28. }
  29. })
  30. }
  31. return routes
  32. }
  33. func getV1ProjectRoutes(
  34. r chi.Router,
  35. config *config.Config,
  36. basePath *types.Path,
  37. factory shared.APIEndpointFactory,
  38. ) ([]*router.Route, *types.Path) {
  39. relPath := "/projects/{project_id}"
  40. newPath := &types.Path{
  41. Parent: basePath,
  42. RelativePath: relPath,
  43. }
  44. var routes []*router.Route
  45. return routes, newPath
  46. }