orb

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 31

Documentation

Overview

Package orb provides the default client for go-orb.

Index

Constants

View Source
const Name = "orb"

Name contains the plugins name.

Variables

View Source
var (
	// Transports is a map of registered transports.
	Transports = container.NewMap[string, TransportFactory]()
)

Functions

func Provide

func Provide(
	name types.ServiceName,
	data types.ConfigData,
	logger log.Logger,
	registry registry.Type,
	opts ...client.Option,
) (client.Type, error)

Provide is the wire provider for client.

func RegisterTransport

func RegisterTransport(name string, transport TransportFactory)

RegisterTransport registers a transport with the orb client.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the microservices client for go-orb.

func New

func New(cfg Config, log log.Logger, registry registry.Type) *Client

New creates a new orb client. This functions should rarely be called manually. To create a new client use ProvideClientOrb.

func (*Client) Call

func (c *Client) Call(
	ctx context.Context,
	req *client.Request[any, any],
	_ any,
	opts ...client.CallOption,
) (resp *client.RawResponse, err error)

Call does the actual call.

func (*Client) CallNoCodec

func (c *Client) CallNoCodec(
	ctx context.Context,
	req *client.Request[any, any],
	result any,
	opts ...client.CallOption,
) error

CallNoCodec does the actual call without codecs.

func (*Client) Config

func (c *Client) Config() client.Config

Config returns the internal config, this is for tests.

func (*Client) NeedsCodec

func (c *Client) NeedsCodec(ctx context.Context, req *client.Request[any, any], opts ...client.CallOption) bool

NeedsCodec returns whetever the underlying transport requires a codec to translate the communication with the server.

func (*Client) ResolveService

func (c *Client) ResolveService(
	_ context.Context,
	service string,
	preferredTransports ...string,
) (client.NodeMap, error)

ResolveService resolves a servicename to a Node with the help of the registry.

func (*Client) Start

func (c *Client) Start() error

Start starts the client.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop stops the client.

func (*Client) String

func (c *Client) String() string

func (*Client) Type

func (c *Client) Type() string

Type returns the clients componenttype "client".

func (*Client) With

func (c *Client) With(opts ...client.Option) error

With closes all transports and configures the client with the given options.

type Config

type Config struct {
	client.Config `yaml:",inline"`
}

Config is the config for the orb client.

func NewConfig

func NewConfig(
	serviceName types.ServiceName,
	datas types.ConfigData,
	opts ...client.Option,
) (Config, error)

NewConfig creates a new config object.

type Transport

type Transport interface {
	Start() error
	Stop(ctx context.Context) error
	String() string

	// NoCodec indicates whatever the transport does the encoding on its own.
	NeedsCodec() bool

	// Call does the actual call to the service, it's important that any errors returned by Call are orberrors.
	Call(ctx context.Context, req *client.Request[any, any], opts *client.CallOptions) (*client.RawResponse, error)

	// CallNoCodec is the same as call but it's using the codec from the transport.
	CallNoCodec(ctx context.Context, req *client.Request[any, any], result any, opts *client.CallOptions) error
}

Transport is the interface for each transport.

type TransportFactory

type TransportFactory = func(log.Logger, *Config) (TransportType, error)

TransportFactory is used by a transports to register itself with the global "Transports" below.

type TransportType

type TransportType struct {
	Transport
}

TransportType is the type returned by NewTransportFunc.

Directories

Path Synopsis
transport
basehertz module
basehttp module
drpc module
grpc module
h2c module
hertzh2c module
hertzhttp module
http module
http3 module
https module

Jump to

Keyboard shortcuts

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