rpc

package
v0.0.0-...-a744df2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 7 Imported by: 8

Documentation

Index

Constants

View Source
const (
	RemoteIDContextKey key = iota

	DefaultResponseBufferLen = 1024
)

Variables

View Source
var (
	ErrNotAFunction = errors.New("not a function")

	ErrInvalidArgsCount = errors.New("invalid argument count")
	ErrInvalidArg       = errors.New("invalid argument, either the type doesn't match or is too complex and can't be inspected")

	ErrClosureDoesNotExist = errors.New("closure does not exist")
)
View Source
var (
	ErrInvalidFunctionCallPath = errors.New("invalid or empty function call path")
	ErrInvalidReturn           = errors.New("invalid return, can only return an error or a value and an error")
	ErrReturnValueTooComplex   = errors.New("invalid return, either the type doesn't match or is too complex and can't be inspected")
	ErrInvalidArgs             = errors.New("invalid arguments, first argument needs to be a context.Context")

	ErrCannotCallNonFunction = errors.New("can not call non function")
)

Functions

func GetRemoteID

func GetRemoteID(ctx context.Context) string

Types

type LinkHooks

type LinkHooks RegistryHooks

type Message

type Message[T any] struct {
	Request  *T `json:"request"`
	Response *T `json:"response"`
}

type Registry

type Registry[R, T any] struct {
	// contains filtered or unexported fields
}

Registry exposes local RPCs and implements remote RPCs

func NewRegistry

func NewRegistry[R, T any](
	local any,

	hooks *RegistryHooks,
) *Registry[R, T]

NewRegistry creates a new registry

func (Registry[R, T]) ForRemotes

func (r Registry[R, T]) ForRemotes(
	cb func(remoteID string, remote R) error,
) error

ForRemotes iterates over the list of connected remotes

func (Registry[R, T]) LinkMessage

func (r Registry[R, T]) LinkMessage(
	ctx context.Context,

	writeRequest,
	writeResponse func(b T) error,

	readRequest,
	readResponse func() (T, error),

	marshal func(v any) (T, error),
	unmarshal func(data T, v any) error,

	hooks *LinkHooks,
) error

LinkMessage exposes local RPCs and implements remote RPCs via a message-based transport

func (Registry[R, T]) LinkStream

func (r Registry[R, T]) LinkStream(
	ctx context.Context,

	encode func(v Message[T]) error,
	decode func(v *Message[T]) error,

	marshal func(v any) (T, error),
	unmarshal func(data T, v any) error,

	hooks *LinkHooks,
) error

LinkStream exposes local RPCs and implements remote RPCs via a stream-based transport

type RegistryHooks

type RegistryHooks struct {
	OnClientConnect    func(remoteID string)
	OnClientDisconnect func(remoteID string)
}

Jump to

Keyboard shortcuts

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