servicerouter

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 2 Imported by: 2

README

tRPC-Go Service Router

Service Router filters nodes between service discovery and load balance to choose a specific node.

Service Router Interface

type ServiceRouter interface {
	Filter(serviceName string, nodes []*registry.Node, opt ...Option) ([]*registry.Node, error)
}

The custom implementation should refer to the implementation inside that project.

Documentation

Overview

Package servicerouter is service router which filters server instances. It is between service discovery and load balance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, s ServiceRouter)

Register registers a named service router.

func SetDefaultServiceRouter

func SetDefaultServiceRouter(s ServiceRouter)

SetDefaultServiceRouter set the default service router.

Types

type NoopServiceRouter

type NoopServiceRouter struct {
}

NoopServiceRouter is the noop service router.

func (*NoopServiceRouter) Filter

func (*NoopServiceRouter) Filter(serviceName string, nodes []*registry.Node, opt ...Option) ([]*registry.Node, error)

Filter returns all nodes.

type Option

type Option func(*Options)

Option modifies the Options.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns an Option which sets request context.

func WithDestinationEnvName

func WithDestinationEnvName(envName string) Option

WithDestinationEnvName returns an Option which sets callee environment name.

func WithDestinationMetadata

func WithDestinationMetadata(key string, val string) Option

WithDestinationMetadata returns an Option which sets callee metadata.

func WithDestinationSetName

func WithDestinationSetName(destinationSetName string) Option

WithDestinationSetName returns an Option which sets callee set name.

func WithDisableServiceRouter

func WithDisableServiceRouter() Option

WithDisableServiceRouter returns an Option which disables service router.

func WithEnvKey

func WithEnvKey(key string) Option

WithEnvKey returns an Option which sets environment key.

func WithEnvTransfer

func WithEnvTransfer(envTransfer string) Option

WithEnvTransfer returns an Option which sets transparent environment information.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace returns an Option which sets namespace.

func WithSourceEnvName

func WithSourceEnvName(envName string) Option

WithSourceEnvName returns an Option which sets caller environment name.

func WithSourceMetadata

func WithSourceMetadata(key string, val string) Option

WithSourceMetadata returns an Option which sets caller metadata.

func WithSourceNamespace

func WithSourceNamespace(namespace string) Option

WithSourceNamespace returns an Option which sets caller namespace.

func WithSourceServiceName

func WithSourceServiceName(serviceName string) Option

WithSourceServiceName returns an Option which sets caller service name.

func WithSourceSetName

func WithSourceSetName(sourceSetName string) Option

WithSourceSetName returns an Option which sets caller set name.

type Options

type Options struct {
	Ctx                  context.Context
	SourceSetName        string
	DestinationSetName   string
	DisableServiceRouter bool
	Namespace            string
	SourceNamespace      string
	SourceServiceName    string
	SourceEnvName        string
	DestinationEnvName   string
	EnvTransfer          string
	EnvKey               string
	SourceMetadata       map[string]string
	DestinationMetadata  map[string]string
}

Options defines the call options.

type ServiceRouter

type ServiceRouter interface {
	Filter(serviceName string, nodes []*registry.Node, opt ...Option) ([]*registry.Node, error)
}

ServiceRouter is the interface that defines the service router.

var DefaultServiceRouter ServiceRouter = &NoopServiceRouter{}

DefaultServiceRouter is the default service router which is initialized by configuration.

func Get

func Get(name string) ServiceRouter

Get gets a named service router.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL