discovery

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: 3 Imported by: 7

README

Service Discovery

Service discovery gets service node list by interacting with service registry center.

Usages

Use client.WithDiscoveryName("xxx") to specify the service discovery.

opts := []client.Option{
	client.WithDiscoveryName("xxxx"),
}
proxy := pb.NewGreeterProxy()
req := &pb.HelloRequest{
	Msg: "trpc-go-client",
}
proxy.SayHello(ctx, req, opts...)

Service Discovery Interface

// Discovery returns node list by service name.
type Discovery interface {
	List(serviceName string, opt ...Option) (nodes []*registry.Node, err error)
}

Refer framework default implementation to how to implement service discovery.

Documentation

Overview

Package discovery is a pluggable service discovery module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, s Discovery)

Register registers a named discovery.

func SetDefaultDiscovery

func SetDefaultDiscovery(d Discovery)

SetDefaultDiscovery sets the default discovery.

Types

type Discovery

type Discovery interface {
	List(serviceName string, opt ...Option) (nodes []*registry.Node, err error)
}

Discovery is the interface that returns nodes by service name.

var DefaultDiscovery Discovery = &IPDiscovery{}

DefaultDiscovery is the default discovery determined by configuration file.

func Get

func Get(name string) Discovery

Get gets a named discovery.

type IPDiscovery

type IPDiscovery struct{}

IPDiscovery discovers node by IPs.

func (*IPDiscovery) List

func (*IPDiscovery) List(serviceName string, opt ...Option) ([]*registry.Node, error)

List returns the original IP/Port.

type Option

type Option func(*Options)

Option modifies the Options.

func WithContext

func WithContext(ctx context.Context) Option

WithContext returns an Option which sets ctx.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace returns an Option which sets namespace.

type Options

type Options struct {
	Ctx       context.Context
	Namespace string
}

Options is the call options.

Jump to

Keyboard shortcuts

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