Documentation ¶
Index ¶
- type Method
- type Registry
- func (reg *Registry) Call(ctx context.Context, req spec.Request, c *conn.Conn) spec.Response
- func (reg *Registry) FindMethod(service, name string) *Method
- func (reg *Registry) FindSubscription(service string, name ...string) *Method
- func (reg *Registry) Register(name string, service interface{}) error
- func (reg *Registry) Subscribe(ctx context.Context, req spec.Notification, c *conn.Conn) *spec.Error
- type Service
- type Subscription
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
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 ¶
Creates new Registry with initialised services map
func (*Registry) Call ¶
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 ¶
Finds method in registry
func (*Registry) FindSubscription ¶
Finds subscription in registry. Subscription in this case is just a method that can be called.
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.