rpc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package rpc implements all available requests and handler for communication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddItem

func AddItem(c *rpc.Client, arg string) error

AddItem sends request over rpc for adding item to the store

func BuildRouter

func BuildRouter() map[string]func(*rpc.Client, string) error

BuildRouter creates map for instant finding handler to any command

func GetAllItems

func GetAllItems(c *rpc.Client, arg string) error

GetAllItems sends request over rpc for retrieving all items in the order they were added

func GetItem

func GetItem(c *rpc.Client, arg string) error

GetItem sends request over rpc for retrieving item from store

func NewClientCodec

func NewClientCodec(conn *amqp.Connection, cfg *configs.Config, encodingCodec EncodingCodec) (rpc.ClientCodec, error)

NewClientCodec returns a new rpc.ClientCodec using AMQP on conn. serverRouting is the routing key with with RPC calls are sent, it should be the same routing key used with NewServerCodec.

func NewClientWithCodec

func NewClientWithCodec(codec rpc.ClientCodec) *rpc.Client

NewClientWithCodec returns rpc client

func NewServerCodec

func NewServerCodec(conn *amqp.Connection, cfg *configs.Config, encodingCodec EncodingCodec) (rpc.ServerCodec, error)

NewServerCodec returns a new rpc.ClientCodec using AMQP on conn. serverRouting is the routing key with with RPC calls are received, encodingCodec is an EncodingCoding implementation.

func Register

func Register(receiver interface{}) error

Register publishes the receiver's methods in the rpc.DefaultServer.

func RemoveItem

func RemoveItem(c *rpc.Client, arg string) error

RemoveItem sends request over rpc for deleting requested item from store

func ServeCodec

func ServeCodec(codec rpc.ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

Types

type EncodingCodec

type EncodingCodec interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

EncodingCodec implements marshaling and unmarshaling of seralized data.

type GobCodec

type GobCodec struct{}

GobCodec is an EncodingCodec implementation to send/receive Gob data over AMQP.

func (GobCodec) Marshal

func (GobCodec) Marshal(v interface{}) ([]byte, error)

func (GobCodec) Unmarshal

func (GobCodec) Unmarshal(data []byte, v interface{}) error

type Items

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

Items stores ordered map and uses for rpc handling

func NewItems

func NewItems() *Items

NewItems creates new instans of Items

func (*Items) AddItem

func (i *Items) AddItem(val string, item *interface{}) error

AddItem adds received item to the ordered map

func (Items) GetAllItems

func (i Items) GetAllItems(val string, items *[]interface{}) error

GetAllItems returns items in order they were added

func (*Items) GetItem

func (i *Items) GetItem(val string, item *interface{}) error

GetItem returns requested item

func (Items) RemoveItem

func (i Items) RemoveItem(val string, deleted *bool) error

RemoveItem deletes item from ordered map and keep order of items

Jump to

Keyboard shortcuts

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