func (a *RingpopRoleServiceAdapter) SetRole(ctx thrift.Context, role string) (err error) {
	if a.config.SetRole == nil || forward.DeleteForwardedHeader(ctx) {
		return a.impl.SetRole(ctx, role)
	}
	ringpopKey, err := a.config.SetRole.Key(ctx, role)
	if err != nil {
		return fmt.Errorf("could not get key: %q", err)
	}
	clientInterface, isRemote, err := a.router.GetClient(ringpopKey)
	if err != nil {
		return err
	}
	client := clientInterface.(TChanRoleService)
	if isRemote {
		ctx = forward.SetForwardedHeader(ctx, []string{ringpopKey})
	}
	return client.SetRole(ctx, role)
}
SetRole satisfies the TChanRoleService interface. This function uses the configuration for SetRole to determine the host to execute the call on. When it decides the call needs to be executed in the current process it will forward the invocation to its local implementation.
package role
import (
	"errors"
	"fmt"
	"github.com/uber/ringpop-go"
	"github.com/uber/ringpop-go/forward"
	"github.com/uber/ringpop-go/router"
	"github.com/uber/tchannel-go"
	"github.com/uber/tchannel-go/thrift"
)
type RingpopRoleServiceAdapter struct {
	impl    TChanRoleService
	ringpop ringpop.Interface
	ch      *tchannel.Channel
	config  RoleServiceConfiguration
	router  router.Router
}
type RoleServiceConfiguration struct {
	GetMembers *RoleServiceGetMembersConfiguration
	SetRole *RoleServiceSetRoleConfiguration
}
func (c *RoleServiceConfiguration) validate() error {
	if c.GetMembers != nil {
		if c.GetMembers.Key == nil {
			return errors.New("configuration for endpoint GetMembers is missing a Key function")
		}
	}
	if c.SetRole != nil {
		if c.SetRole.Key == nil {
			return errors.New("configuration for endpoint SetRole is missing a Key function")
		}
	}
	return nil
}
func NewRingpopRoleServiceAdapter(
	impl TChanRoleService,
	rp ringpop.Interface,
	ch *tchannel.Channel,
	config RoleServiceConfiguration,
) (TChanRoleService, error) {
	err := config.validate()
	if err != nil {
		return nil, err
	}
	adapter := &RingpopRoleServiceAdapter{
		impl:    impl,
		ringpop: rp,
		ch:      ch,
		config:  config,
	}
	adapter.router = router.New(rp, adapter, ch)
	return adapter, nil
}
func (a *RingpopRoleServiceAdapter) GetLocalClient() interface{} {
	return a.impl
}
func (a *RingpopRoleServiceAdapter) MakeRemoteClient(client thrift.TChanClient) interface{} {
	return NewTChanRoleServiceClient(client)
}
type RoleServiceGetMembersConfiguration struct {
	Key func(ctx thrift.Context, role string) (string, error)
}
func (a *RingpopRoleServiceAdapter) GetMembers(ctx thrift.Context, role string) (r []string, err error) {
	if a.config.GetMembers == nil || forward.DeleteForwardedHeader(ctx) {
		return a.impl.GetMembers(ctx, role)
	}
	ringpopKey, err := a.config.GetMembers.Key(ctx, role)
	if err != nil {
		return r, fmt.Errorf("could not get key: %q", err)
	}
	clientInterface, isRemote, err := a.router.GetClient(ringpopKey)
	if err != nil {
		return r, err
	}
	client := clientInterface.(TChanRoleService)
	if isRemote {
		ctx = forward.SetForwardedHeader(ctx, []string{ringpopKey})
	}
	return client.GetMembers(ctx, role)
}
type RoleServiceSetRoleConfiguration struct {
	Key func(ctx thrift.Context, role string) (string, error)
}