16306: Merge branch 'master'
[arvados.git] / lib / controller / api / routable.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 // Package api provides types used by controller/server-component
6 // packages.
7 package api
8
9 import "context"
10
11 // A RoutableFunc calls an API method (sometimes via a wrapped
12 // RoutableFunc) that has real argument types.
13 //
14 // (It is used by ctrlctx to manage database transactions, so moving
15 // it to the router package would cause a circular dependency
16 // router->arvadostest->ctrlctx->router.)
17 type RoutableFunc func(ctx context.Context, opts interface{}) (interface{}, error)
18
19 type RoutableFuncWrapper func(RoutableFunc) RoutableFunc
20
21 // ComposeWrappers (w1, w2, w3, ...) returns a RoutableFuncWrapper that
22 // composes w1, w2, w3, ... such that w1 is the outermost wrapper.
23 func ComposeWrappers(wraps ...RoutableFuncWrapper) RoutableFuncWrapper {
24         return func(f RoutableFunc) RoutableFunc {
25                 for i := len(wraps) - 1; i >= 0; i-- {
26                         f = wraps[i](f)
27                 }
28                 return f
29         }
30 }