blob: 83f6e2fb5a9acc5fd35cd8eb64eb5c0d27a778de [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// Copyright 2015 The Vanadium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Bogdan Caprita7590a6d2015-01-08 13:43:40 -08005package testutil
6
7import (
Cosmos Nicolaou5a3125a2015-07-10 11:19:20 -07008 "v.io/v23/context"
Matt Rosencrantz94502cf2015-03-18 09:43:44 -07009 "v.io/v23/rpc"
Jiri Simsa6ac95222015-02-23 16:11:49 -080010 "v.io/v23/security"
Cosmos Nicolaou185c0c62015-04-13 21:22:43 -070011 "v.io/v23/verror"
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080012)
13
14// LeafDispatcher returns a dispatcher for a single object obj, using
15// ReflectInvokerOrDie to invoke methods. Lookup only succeeds on the empty
16// suffix. The provided auth is returned for successful lookups.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070017func LeafDispatcher(obj interface{}, auth security.Authorizer) rpc.Dispatcher {
18 return &leafDispatcher{rpc.ReflectInvokerOrDie(obj), auth}
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080019}
20
21type leafDispatcher struct {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070022 invoker rpc.Invoker
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080023 auth security.Authorizer
24}
25
Cosmos Nicolaou5a3125a2015-07-10 11:19:20 -070026func (d leafDispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) {
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080027 if suffix != "" {
Cosmos Nicolaou185c0c62015-04-13 21:22:43 -070028 return nil, nil, verror.New(verror.ErrUnknownSuffix, nil, suffix)
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080029 }
30 return d.invoker, d.auth, nil
31}