drpc

package module
v0.0.0-...-191046f Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 25 Imported by: 10

Documentation

Overview

Package drpc provides the drpc server for go-orb.

Package drpc provides a drpc mux that handles orb middleware.

Index

Constants

View Source
const (
	// DefaultAddress to use for new dRPC servers.
	DefaultAddress = ":0"

	// DefaultMaxConcurrentStreams for dRPC.
	DefaultMaxConcurrentStreams = 256
)
View Source
const Plugin = "drpc"

Plugin is the plugin name.

Variables

View Source
var (
	// ErrInvalidConfigType is returned when you provided an invalid config type.
	ErrInvalidConfigType = errors.New("drpc server: invalid config type provided, not of type drpc.Config")
)

Errors.

Functions

func New

func New(acfg any, logger log.Logger, reg registry.Type) (orbserver.Entrypoint, error)

New creates a dRPC Server from a Config struct.

func Provide

func Provide(
	sections []string,
	configs types.ConfigData,
	logger log.Logger,
	reg registry.Type,
	opts ...orbserver.Option,
) (orbserver.Entrypoint, error)

Provide creates a new entrypoint for a single address. You can create multiple entrypoints for multiple addresses and ports.

func WithAddress

func WithAddress(address string) server.Option

WithAddress specifies the address to listen on. If you want to listen on all interfaces use the format "[::]:8080" If you want to listen on a specific interface/address use the full IP.

func WithHandlers

func WithHandlers(h ...server.RegistrationFunc) server.Option

WithHandlers adds custom handlers.

func WithListener

func WithListener(l net.Listener) server.Option

WithListener sets the entrypoints listener. This overwrites `Address`.

func WithLogLevel

func WithLogLevel(level string) server.Option

WithLogLevel changes the log level from the inherited logger.

func WithLogPlugin

func WithLogPlugin(plugin string) server.Option

WithLogPlugin changes the log level from the inherited logger.

func WithMaxConcurrentStreams

func WithMaxConcurrentStreams(n int) server.Option

WithMaxConcurrentStreams sets the worker pool size.

func WithMiddleware

func WithMiddleware(m string) server.Option

WithMiddleware adds a pre-registered middleware.

func WithName

func WithName(name string) server.Option

WithName sets the entrypoint name. The default name is in the format of 'drpc-<uuid>'.

Setting a custom name allows you to dynamically reference the entrypoint in the file config, and makes it easier to attribute the logs.

Types

type Config

type Config struct {
	server.EntrypointConfig `yaml:",inline"`

	// Listener can be used to provide your own Listener, when in use `Address` is obsolete.
	Listener net.Listener `json:"-" yaml:"-"`

	// Address to listen on.
	// If no port is provided, a random port will be selected. To listen on a
	// specific interface, but with a random port, you can use '<IP>:0'.
	Address string `json:"address" yaml:"address"`

	// MaxConcurrentStreams is the worker pool size.
	MaxConcurrentStreams int `json:"maxConcurrentStreams" yaml:"maxConcurrentStreams"`

	// Middlewares is a list of middleware to use.
	Middlewares []server.MiddlewareConfig `json:"middlewares" yaml:"middlewares"`

	// Handlers is a list of pre-registered handlers.
	Handlers []string `json:"handlers" yaml:"handlers"`

	// Logger allows you to dynamically change the log level and plugin for a
	// specific entrypoint.
	Logger log.Config `json:"logger" yaml:"logger"`
}

Config provides options to the entrypoint.

func NewConfig

func NewConfig(options ...server.Option) *Config

NewConfig will create a new default config for the entrypoint.

type Mux

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

Mux is an implementation of Handler to serve drpc connections to the appropriate Receivers registered by Descriptions.

func (*Mux) HandleRPC

func (m *Mux) HandleRPC(stream drpc.Stream, rpc string) (err error)

HandleRPC handles the rpc that has been requested by the stream.

func (*Mux) Register

func (m *Mux) Register(srv interface{}, desc drpc.Description) error

Register associates the RPCs described by the description in the server. It returns an error if there was a problem registering it.

type Server

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

Server is the drpc Server for go-orb.

func (*Server) AddEndpoint

func (s *Server) AddEndpoint(name string)

AddEndpoint add's an endpoint to the internal list. This is used by the Register() callback function.

func (*Server) Address

func (s *Server) Address() string

Address returns the address the entrypoint is listening on, for example: [::]:8381.

func (*Server) Enabled

func (s *Server) Enabled() bool

Enabled returns if this entrypoint has been enbaled in config.

func (*Server) EntrypointID

func (s *Server) EntrypointID() string

EntrypointID returns the id (uuid) of this entrypoint in the registry.

func (*Server) Name

func (s *Server) Name() string

Name returns the entrypoint name.

func (*Server) Register

func (s *Server) Register(register orbserver.RegistrationFunc)

Register executes a registration function on the entrypoint.

func (*Server) Router

func (s *Server) Router() *Mux

Router returns the drpc mux.

func (*Server) Start

func (s *Server) Start() error

Start will create the listeners and start the server on the entrypoint.

func (*Server) Stop

func (s *Server) Stop(_ context.Context) error

Stop will stop the dRPC server.

func (*Server) String

func (s *Server) String() string

String returns the entrypoint type.

func (*Server) Transport

func (s *Server) Transport() string

Transport returns the client transport to use: "drpc".

func (*Server) Type

func (s *Server) Type() string

Type returns the component type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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