X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/865e5c1e3730117870eb1e485d553383626b882f..a6b9fb8166440eef3144150024a875c858db9bb6:/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 + } +}