registry

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Method

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

Method represents function in struct to be called. Registering struct with registry reflects all methods as Method

func (*Method) Call

func (m *Method) Call(ctx context.Context, method string, args []reflect.Value, sub *Subscription) (res interface{}, errRes error)

Executes function with given parameters. If a method is subscription it passes Subscription that holds write channel using Subscription.Notify().

func (*Method) ParseArgs

func (m *Method) ParseArgs(params interface{}) ([]reflect.Value, error)

Transforms params interface coming from json parsed object to reflect values. It is neccessary to Call a Method.

type Registry

type Registry struct {
	// Flag to turn on/off logs for server
	LogsOn bool
	// contains filtered or unexported fields
}

Register struct as a service for jrpc-ws to handle automatically. Keeps track of subscriptions.

func NewRegistry

func NewRegistry(logsOn bool) *Registry

Creates new Registry with initialised services map

func (*Registry) Call

func (reg *Registry) Call(ctx context.Context, req spec.Request, c *conn.Conn) spec.Response

Call a method based on json-rpc Request. If a request is notification a Notification struct will be initialised and write channel attached to it. Returns response and ShouldReply flag.

func (*Registry) FindMethod

func (reg *Registry) FindMethod(service, name string) *Method

Finds method in registry

func (*Registry) FindSubscription

func (reg *Registry) FindSubscription(service string, name ...string) *Method

Finds subscription in registry. Subscription in this case is just a method that can be called.

func (*Registry) Register

func (reg *Registry) Register(name string, service interface{}) error

Register struct methods in registry. This should be called when server is initialised.

func (*Registry) Subscribe added in v0.0.15

func (reg *Registry) Subscribe(ctx context.Context, req spec.Notification, c *conn.Conn) *spec.Error

Notify a method based on json-rpc Request. If a request is notification a Notification struct will be initialised and write channel attached to it.

type Service

type Service struct {
	Name string
	// contains filtered or unexported fields
}

Service represents struct with its methods and is registered with a name

type Subscription

type Subscription struct {
	// Flag to turn on/off logs for server
	LogsOn bool

	// ID provided by client request
	MessageID interface{}

	// Pointer to connection used to send data
	Conn *conn.Conn

	// Exit chanel will be closed if an "unsubscribe" is called or on error
	Exit chan interface{}
	// contains filtered or unexported fields
}

Subscription should be attached to any function that is ment to serve as a subscription. Just includine "func x(sub *Subscription) error" will mean that it will be used as subscription and should block the thread while its used.

func NewSubscription added in v0.0.2

func NewSubscription(methodName string, id interface{}, c *conn.Conn, logsOn bool) *Subscription

Creates new Subscription with its name and write channel. Returns nil if chanel is not provided.

func (*Subscription) Close added in v0.0.15

func (s *Subscription) Close()

func (*Subscription) ID added in v0.0.15

func (s *Subscription) ID() string

Unique key used to keep track of subscriptions. Key = Conn.ID + sub.methodName

func (*Subscription) IsRunning added in v0.0.15

func (s *Subscription) IsRunning() bool

When handling subscription from struct use this function as a safety check. If returns false connection is closed or sub unsubscribed and handler loop should break.

func (*Subscription) Notify added in v0.0.2

func (s *Subscription) Notify(data interface{}) error

Sends json-rpc Notification to the open connection.

Jump to

Keyboard shortcuts

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