X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e8d1a643cdbc3a5f4c0e5c745da58d9f7e1248d8..4aa26076d2c7ed1f2a84ee0c5e9c63ab30ace530:/lib/controller/api/routable.go diff --git a/lib/controller/api/routable.go b/lib/controller/api/routable.go index 6049cba8e4..f887448829 100644 --- a/lib/controller/api/routable.go +++ b/lib/controller/api/routable.go @@ -15,3 +15,16 @@ import "context" // it to the router package would cause a circular dependency // router->arvadostest->ctrlctx->router.) type RoutableFunc func(ctx context.Context, opts interface{}) (interface{}, error) + +type RoutableFuncWrapper func(RoutableFunc) RoutableFunc + +// ComposeWrappers (w1, w2, w3, ...) returns a RoutableFuncWrapper that +// composes w1, w2, w3, ... such that w1 is the outermost wrapper. +func ComposeWrappers(wraps ...RoutableFuncWrapper) RoutableFuncWrapper { + return func(f RoutableFunc) RoutableFunc { + for i := len(wraps) - 1; i >= 0; i-- { + f = wraps[i](f) + } + return f + } +}