mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions) for a top-level namespace
(route martini.Router, namespace *schema.Namespace)
| 476 | // mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions) |
| 477 | // for a top-level namespace |
| 478 | func 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 |
no test coverage detected