1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 20:07:04 +00:00

examples: writing an API for the Apache Kafka: add a root handler for routes documentation to make navigation easier and add some other methods that may find them useful for request state and routes description

Former-commit-id: 3775aab2386051b23e127ccc9e3a6accdfdee6d0
This commit is contained in:
Gerasimos (Makis) Maropoulos
2018-08-05 13:51:05 +03:00
parent 2b2492abfa
commit e5f6bce86f
8 changed files with 97 additions and 2 deletions

View File

@@ -437,6 +437,7 @@ func (api *APIBuilder) GetRoute(routeName string) *Route {
// One note: "routeName" should be case-sensitive. Used by the context to get the current route.
// It returns an interface instead to reduce wrong usage and to keep the decoupled design between
// the context and the routes.
// Look `GetRoutesReadOnly` to fetch a list of all registered routes.
//
// Look `GetRoute` for more.
func (api *APIBuilder) GetRouteReadOnly(routeName string) context.RouteReadOnly {
@@ -447,6 +448,24 @@ func (api *APIBuilder) GetRouteReadOnly(routeName string) context.RouteReadOnly
return routeReadOnlyWrapper{r}
}
// GetRoutesReadOnly returns the registered routes with "read-only" access,
// you cannot and you should not change any of these routes' properties on request state,
// you can use the `GetRoutes()` for that instead.
//
// It returns interface-based slice instead of the real ones in order to apply
// safe fetch between context(request-state) and the builded application.
//
// Look `GetRouteReadOnly` too.
func (api *APIBuilder) GetRoutesReadOnly() []context.RouteReadOnly {
routes := api.GetRoutes()
readOnlyRoutes := make([]context.RouteReadOnly, len(routes))
for i, r := range routes {
readOnlyRoutes[i] = routeReadOnlyWrapper{r}
}
return readOnlyRoutes
}
// Use appends Handler(s) to the current Party's routes and child routes.
// If the current Party is the root, then it registers the middleware to all child Parties' routes too.
//