blob: 671f4d60c1b1f197c9d1fa62819b9189f12503fc [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 (
Matt Rosencrantz94502cf2015-03-18 09:43:44 -07008 "v.io/v23/rpc"
Jiri Simsa6ac95222015-02-23 16:11:49 -08009 "v.io/v23/security"
Cosmos Nicolaou185c0c62015-04-13 21:22:43 -070010 "v.io/v23/verror"
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080011)
12
13// LeafDispatcher returns a dispatcher for a single object obj, using
14// ReflectInvokerOrDie to invoke methods. Lookup only succeeds on the empty
15// suffix. The provided auth is returned for successful lookups.
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070016func LeafDispatcher(obj interface{}, auth security.Authorizer) rpc.Dispatcher {
17 return &leafDispatcher{rpc.ReflectInvokerOrDie(obj), auth}
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080018}
19
20type leafDispatcher struct {
Matt Rosencrantz94502cf2015-03-18 09:43:44 -070021 invoker rpc.Invoker
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080022 auth security.Authorizer
23}
24
25func (d leafDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
26 if suffix != "" {
Cosmos Nicolaou185c0c62015-04-13 21:22:43 -070027 return nil, nil, verror.New(verror.ErrUnknownSuffix, nil, suffix)
Bogdan Caprita7590a6d2015-01-08 13:43:40 -080028 }
29 return d.invoker, d.auth, nil
30}