blob: 671f4d60c1b1f197c9d1fa62819b9189f12503fc [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testutil
import (
// LeafDispatcher returns a dispatcher for a single object obj, using
// ReflectInvokerOrDie to invoke methods. Lookup only succeeds on the empty
// suffix. The provided auth is returned for successful lookups.
func LeafDispatcher(obj interface{}, auth security.Authorizer) rpc.Dispatcher {
return &leafDispatcher{rpc.ReflectInvokerOrDie(obj), auth}
type leafDispatcher struct {
invoker rpc.Invoker
auth security.Authorizer
func (d leafDispatcher) Lookup(suffix string) (interface{}, security.Authorizer, error) {
if suffix != "" {
return nil, nil, verror.New(verror.ErrUnknownSuffix, nil, suffix)
return d.invoker, d.auth, nil