grpcs

package
v0.0.0-...-047dcd9 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	In  = true
	Out = false

	TypeBool        = true
	TypeString      = ""
	TypeStringSlice = []string{""}
	TypeByteSlice   = []byte("")
	TypeIF          = ginterface.UnInitIF
	TypeIFSlice     []interface{}
	StringSlice     []string
)
View Source
var (
	RpcTypeGOB    = RpcType("gob")
	RpcTypeJSON   = RpcType("json")
	RpcTypeHPROSE = RpcType("hprose")
)

Functions

This section is empty.

Types

type Client

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

func Dial

func Dial(rpcType RpcType, network, address string, checker ParamChecker) (*Client, error)

func (*Client) Call

func (c *Client) Call(name string, args Request, reply *Reply) error

func (*Client) Close

func (c *Client) Close() error

type InitChecker

type InitChecker func() ParamChecker

type OnRequest

type OnRequest func(in Request, out *Reply) error

type ParamChecker

type ParamChecker struct {
	InRequirements  map[string]map[string]interface{}
	OutRequirements map[string]map[string]interface{}
}

func NewParamChecker

func NewParamChecker() *ParamChecker

func (*ParamChecker) Require

func (pc *ParamChecker) Require(function string, isIn bool, name string, typeSample interface{})

Require param with specified type. Type of initialized interface{} like interface{}(”) is string, not interface{}. Type of uninitialized interface{} is 'nil'. If requires uninitialized interface{} type to allow multiple param types, set typeSample as 'nil',

func (*ParamChecker) RequireIF

func (pc *ParamChecker) RequireIF(function string, isIn bool, name string)

Require interface{} param. 'nil' means uninitialized interface{} param, interface{} type param doesn't need to check type.

func (*ParamChecker) VerifyIn

func (pc *ParamChecker) VerifyIn(function string, in Request) error

func (*ParamChecker) VerifyOut

func (pc *ParamChecker) VerifyOut(function string, out *Reply, fuzzyNumSlice bool) error

If set 'fuzzyNumSlice' true, consider []uint8 / []uint16 ... []int64 as []float64 because after json.Unmarshal([]byte, &interface{}), output interface is set as map[string]interface{}, and any type number map value is float64 type.

type Proxy

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

func NewProxy

func NewProxy(clientRpcType RpcType, clientNetwork, clientAddress string,
	serverRpcType RpcType, serverNetwork, serverAddress string) (*Proxy, error)

build new proxy

func (*Proxy) AddAllowFunc

func (p *Proxy) AddAllowFunc(fn string)

func (*Proxy) AddCacheFunc

func (p *Proxy) AddCacheFunc(fn string)

Add function names which need to cache.

func (*Proxy) Close

func (p *Proxy) Close() error

func (*Proxy) Run

func (p *Proxy) Run() error

type Reply

type Reply map[string]interface{}

func NewReply

func NewReply() Reply

func (*Reply) Get

func (p *Reply) Get(key string) interface{}

func (*Reply) Set

func (p *Reply) Set(key string, val interface{})

type Request

type Request struct {
	Func   string
	Params map[string]interface{}
}

func NewRequest

func NewRequest() Request

func (*Request) Get

func (p *Request) Get(key string) interface{}

func (*Request) Set

func (p *Request) Set(key string, val interface{})

type RpcType

type RpcType string

type Server

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

func Listen

func Listen(rpcType RpcType, network, address string) (*Server, error)

func (*Server) Close

func (s *Server) Close() error

func (*Server) Run

func (s *Server) Run(checker ParamChecker, onReq OnRequest) error

Before every 'onReq' call, rpc server will check input and out put param with 'checker'.

type Svr

type Svr Server

func (*Svr) OnRequestInternal

func (s *Svr) OnRequestInternal(in Request, out *Reply) error

Jump to

Keyboard shortcuts

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