rpcx

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package rpcx

@author: xwc1125

Package rpcx

@author: xwc1125

Package rpcx

@author: xwc1125

Index

Constants

This section is empty.

Variables

View Source
var (
	JsonRpcVersion         = "2.0"
	ServiceMethodSeparator = "."
	Debug                  = false
)

Functions

This section is empty.

Types

type API

type API struct {
	Namespace     string      // 对外的命名空间
	Version       string      // api版本
	Public        bool        // 可供公众使用
	Service       interface{} // 方法集合
	Authenticated bool        // 是否提供认证后才能访问
}

type Error

type Error interface {
	Error() string  // returns the message
	ErrorCode() int // returns the code
}
type Header map[string][]string

type JsonError

type JsonError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func (JsonError) String

func (j JsonError) String() string

type JsonResponse

type JsonResponse struct {
	Version string      `json:"jsonrpc,omitempty"`
	Id      interface{} `json:"id,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Error   error       `json:"error,omitempty"`
}

func (JsonResponse) MarshalJSON

func (j JsonResponse) MarshalJSON() ([]byte, error)

func (JsonResponse) String

func (j JsonResponse) String() string

type Method

type Method struct {
	Method   string   `json:"method" mapstructure:"method" yaml:"method"`
	ArgsType []string `json:"argsType,omitempty" mapstructure:"method,omitempty" yaml:"method,omitempty"`
}

type Namespace

type Namespace struct {
	Namespace string    `json:"namespace"`
	Methods   []*Method `json:"methods"`
}

type RPC

type RPC interface {
	// Register 注册命名及其类方法[对外暴露的方法必须是首字母大写]
	// namespace 命名空间
	// rcvr 服务对象(函数类)
	Register(namespace string, rcvr interface{}) error
	// Exec 执行
	// namespace 命名空间
	// method 方法名称
	// reqId 请求的ID
	// params 请求的参数
	Exec(ctx context.Context, namespace string, method string, reqId interface{}, params ...interface{}) *JsonResponse

	Namespaces(ctx context.Context) []*Namespace
	Namespaces2(ctx context.Context) map[string]map[string]*Method
}

RPC rpc 的接口

func New

func New() RPC

New 创建rpc

type RPCX

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

RPCX rpcx

func (*RPCX) Exec

func (r *RPCX) Exec(ctx context.Context, namespace string, method string, reqId interface{}, params ...interface{}) *JsonResponse

Exec 执行

func (*RPCX) Namespaces

func (r *RPCX) Namespaces(ctx context.Context) []*Namespace

func (*RPCX) Namespaces2

func (r *RPCX) Namespaces2(ctx context.Context) map[string]map[string]*Method

func (*RPCX) Register

func (r *RPCX) Register(namespace string, rcvr interface{}) error

Register 注册

Jump to

Keyboard shortcuts

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