Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // 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 Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 5 | package testutil |
| 6 | |
| 7 | import ( |
Cosmos Nicolaou | 5a3125a | 2015-07-10 11:19:20 -0700 | [diff] [blame] | 8 | "v.io/v23/context" |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 9 | "v.io/v23/rpc" |
Jiri Simsa | 6ac9522 | 2015-02-23 16:11:49 -0800 | [diff] [blame] | 10 | "v.io/v23/security" |
Cosmos Nicolaou | 185c0c6 | 2015-04-13 21:22:43 -0700 | [diff] [blame] | 11 | "v.io/v23/verror" |
Bogdan Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 12 | ) |
| 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 Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 17 | func LeafDispatcher(obj interface{}, auth security.Authorizer) rpc.Dispatcher { |
| 18 | return &leafDispatcher{rpc.ReflectInvokerOrDie(obj), auth} |
Bogdan Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | type leafDispatcher struct { |
Matt Rosencrantz | 94502cf | 2015-03-18 09:43:44 -0700 | [diff] [blame] | 22 | invoker rpc.Invoker |
Bogdan Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 23 | auth security.Authorizer |
| 24 | } |
| 25 | |
Cosmos Nicolaou | 5a3125a | 2015-07-10 11:19:20 -0700 | [diff] [blame] | 26 | func (d leafDispatcher) Lookup(_ *context.T, suffix string) (interface{}, security.Authorizer, error) { |
Bogdan Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 27 | if suffix != "" { |
Cosmos Nicolaou | 185c0c6 | 2015-04-13 21:22:43 -0700 | [diff] [blame] | 28 | return nil, nil, verror.New(verror.ErrUnknownSuffix, nil, suffix) |
Bogdan Caprita | 7590a6d | 2015-01-08 13:43:40 -0800 | [diff] [blame] | 29 | } |
| 30 | return d.invoker, d.auth, nil |
| 31 | } |