MCPcopy Create free account
hub / github.com/cloudwan/gohan / mapTopLevelNamespaceRoute

Function mapTopLevelNamespaceRoute

server/api.go:478–505  ·  view source on GitHub ↗

mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions) for a top-level namespace

(route martini.Router, namespace *schema.Namespace)

Source from the content-addressed store, hash-verified

476// mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions)
477// for a top-level namespace
478func mapTopLevelNamespaceRoute(route martini.Router, namespace *schema.Namespace) {
479 log.Debug("[Path] %s/", namespace.GetFullPrefix())
480 route.Get(
481 namespace.GetFullPrefix()+"/",
482 func(w http.ResponseWriter, r *http.Request, p martini.Params, context martini.Context) {
483 versions := []schema.Version{}
484 for _, childNamespace := range schema.GetManager().Namespaces() {
485 if childNamespace.Parent == namespace.ID {
486 versions = append(versions, schema.Version{
487 Status: "SUPPORTED",
488 ID: childNamespace.Prefix,
489 Links: []schema.Link{
490 {
491 Href: childNamespace.GetFullPrefix() + "/",
492 Rel: "self",
493 },
494 },
495 })
496 }
497 }
498
499 if len(versions) != 0 {
500 versions[len(versions)-1].Status = "CURRENT"
501 }
502
503 routes.ServeJson(w, map[string][]schema.Version{"versions": versions})
504 })
505}
506
507// mapChildNamespaceRoute sets a handler returning a dictionary of resources
508// supported by a certain API version identified by the given namespace

Callers 1

MapNamespacesRoutesFunction · 0.85

Calls 4

GetFullPrefixMethod · 0.80
NamespacesMethod · 0.80
DebugMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected