rpcgroup

package
v0.0.0-...-431d825 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Example:

var group = rpcgroup.New(5000, "app1:5000", "app2:5000")
func init() {
	id := "0001"
	group.Call(InitializeFunction, id)
}
var InitializeFunction = rpcgroup.Register(func(id string) {
	StartLogger(id)
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(name string, params ...interface{}) []interface{}

Call a function named as "name" with argments params... Before calling this function, you need to first call Register.

func GetFunctionNameOrString

func GetFunctionNameOrString(f interface{}) string

func GobRegister

func GobRegister(d interface{})

GobRegister registers your struct If error "panic: gob: type not registered for interface: YOUR STRUCT" happens. (Example: cluster.GobRegister(MyStruct{}))

func Hostname

func Hostname() string

Hostname returns host name or "" if there is an error

func Listen

func Listen(listenPort int)

func Register

func Register(f interface{}) string

Register registers a function to call over network. Every function that is called by RPC must be registered before its call. Return value: registered function name

func RegisterAs

func RegisterAs(name string, f interface{})

Register registers a function using a name

Types

type CallArgs

type CallArgs struct {
	Name string
	Arg  []interface{}
}

type Client

type Client struct {
	// The connection destination.  e.g., "localhost:5000"
	TargetHost string

	// The number of times that try to reconnect.  if this is negative, retry connection forever.
	RetryCount int64
	// contains filtered or unexported fields
}

func NewClient

func NewClient(TargetHost string) *Client

func (*Client) Call

func (c *Client) Call(name string, params ...interface{}) []interface{}

func (*Client) Connect

func (c *Client) Connect()

Connect connects to the server if the connection is not established yet.

type Dummy

type Dummy struct {
}

For net/rpc

func (*Dummy) Call

func (t *Dummy) Call(args *CallArgs, reply *[]interface{}) error

type FunctionCallRequest

type FunctionCallRequest struct {
	CallArgs
	Channel chan *rpc.Call
}

type Group

type Group struct {
	MyHost  string
	Clients []*Client
}

func GroupWithoutListen

func GroupWithoutListen(hosts ...string) *Group

GroupWithoutListen is a constructor of Group that does not listen any port. It groups together all the hosts.

func New

func New(listenPort int, hosts ...string) *Group

New is a constructor of Group. hosts must be specified by the "host:port" form.

func (*Group) Call

func (c *Group) Call(f interface{}, params ...interface{}) [][]interface{}

func (*Group) Client

func (c *Group) Client(id int) *Client

Client returns the id'th client (0-indexed)

func (*Group) Subgroup

func (c *Group) Subgroup(indices []int) *Group

Subgroup returns a sub-group of Group.

Jump to

Keyboard shortcuts

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