mqrpc

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2014 loolgame Author. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrNil = errors.New("mqrpc: nil returned")

Functions

func Bool

func Bool(reply interface{}, err interface{}) (bool, error)

Bool is a helper that converts a command reply to a boolean. If err is not equal to nil, then Bool returns false, err. Otherwise Bool converts the reply to boolean as follows:

Reply type      Result
integer         value != 0, nil
bulk string     strconv.ParseBool(reply)
nil             false, ErrNil
other           false, error

func Bytes

func Bytes(reply interface{}, err interface{}) ([]byte, error)

Bytes is a helper that converts a command reply to a slice of bytes. If err is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts the reply to a slice of bytes as follows:

Reply type      Result
bulk string     reply, nil
simple string   []byte(reply), nil
nil             nil, ErrNil
other           nil, error

func Float64

func Float64(reply interface{}, err interface{}) (float64, error)

Float64 is a helper that converts a command reply to 64 bit float. If err is not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts the reply to an int as follows:

Reply type    Result
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func Int

func Int(reply interface{}, err interface{}) (int, error)

func Int64

func Int64(reply interface{}, err interface{}) (int64, error)

Int64 is a helper that converts a command reply to 64 bit integer. If err is not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the reply to an int64 as follows:

Reply type    Result
integer       reply, nil
bulk string   parsed reply, nil
nil           0, ErrNil
other         0, error

func InterfaceMap

func InterfaceMap(reply interface{}, err interface{}) (map[string]interface{}, error)

func Marshal

func Marshal(mrsp interface{}, ff func() (reply interface{}, err interface{})) error

func Proto

func Proto(mrsp interface{}, ff func() (reply interface{}, err interface{})) error

func String

func String(reply interface{}, err interface{}) (string, error)

String is a helper that converts a command reply to a string. If err is not equal to nil, then String returns "", err. Otherwise String converts the reply to a string as follows:

Reply type      Result
bulk string     string(reply), nil
simple string   reply, nil
nil             "",  ErrNil
other           "",  error

func StringMap

func StringMap(reply interface{}, err interface{}) (map[string]string, error)

StringMap is a helper that converts an array of strings (alternating key, value) into a map[string]string. The HGETALL and CONFIG GET commands return replies in this format. Requires an even number of values in result.

Types

type CallInfo

type CallInfo struct {
	RpcInfo  rpcpb.RPCInfo
	Result   rpcpb.ResultInfo
	Props    map[string]interface{}
	ExecTime int64
	Agent    MQServer //代理者  AMQPServer / LocalServer 都继承 Callback(callinfo CallInfo)(error) 方法
}

type FunctionInfo

type FunctionInfo struct {
	Function  reflect.Value
	Goroutine bool
}

type GoroutineControl

type GoroutineControl interface {
	Wait() error
	Finish()
}

type LocalClient

type LocalClient interface {
	Done() error
	Call(callInfo CallInfo, callback chan rpcpb.ResultInfo) (err error)
	CallNR(callInfo CallInfo) (err error)
}

type LocalServer

type LocalServer interface {
	IsClose() bool
	Write(callInfo CallInfo) error
	StopConsume() error
	Shutdown() (err error)
	Callback(callinfo CallInfo) error
}

type MQServer

type MQServer interface {
	Callback(callinfo CallInfo) error
}

type Marshaler

type Marshaler interface {
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	String() string
}

Marshaler is a simple encoding interface used for the broker/transport where headers are not supported by the underlying implementation.

type ParamOption

type ParamOption func() []interface{}

func Param

func Param(params ...interface{}) ParamOption

type RPCClient

type RPCClient interface {
	Done() (err error)
	CallArgs(ctx context.Context, _func string, ArgsType []string, args [][]byte) (interface{}, string)
	CallNRArgs(_func string, ArgsType []string, args [][]byte) (err error)
	Call(ctx context.Context, _func string, params ...interface{}) (interface{}, string)
	CallNR(_func string, params ...interface{}) (err error)
}

type RPCListener

type RPCListener interface {
	/**
	BeforeHandle会对请求做一些前置处理,如:检查当前玩家是否已登录,打印统计日志等。
	@session  可能为nil
	return error  当error不为nil时将直接返回改错误信息而不会再执行后续调用
	*/
	NoFoundFunction(fn string) (*FunctionInfo, error)
	BeforeHandle(fn string, callInfo *CallInfo) error
	OnTimeOut(fn string, Expired int64)
	OnError(fn string, callInfo *CallInfo, err error)
	/**
	fn 		方法名
	params		参数
	result		执行结果
	exec_time 	方法执行时间 单位为 Nano 纳秒  1000000纳秒等于1毫秒
	*/
	OnComplete(fn string, callInfo *CallInfo, result *rpcpb.ResultInfo, exec_time int64)
}

type RPCServer

type RPCServer interface {
	Addr() string
	SetListener(listener RPCListener)
	SetGoroutineControl(control GoroutineControl)
	GetExecuting() int64
	Register(id string, f interface{})
	RegisterGO(id string, f interface{})
	Done() (err error)
}

Directories

Path Synopsis
Package rpcpb is a generated protocol buffer package.
Package rpcpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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