rpcx

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsulRegister

func ConsulRegister(conf ServerConfig) (server.Plugin, error)

func CustomOptions

func CustomOptions(f func() client.Option)

func EtcdV3Register

func EtcdV3Register(conf ServerConfig) (server.Plugin, error)

func ZooKeeperRegister

func ZooKeeperRegister(conf ServerConfig) (server.Plugin, error)

Types

type AuthFunc

type AuthFunc func(ctx context.Context, token string) error

type BalanceModel

type BalanceModel int

BalanceModel 负载均衡模式

const (
	// Random 随机
	Random BalanceModel = iota + 1
	// RoundRobin 轮询
	RoundRobin
	// ConsistentHash 一致性哈希
	ConsistentHash
	// NetworkQuality 网络质量
	NetworkQuality
)

type ClientConfig

type ClientConfig struct {
	ClientName      string
	BasePath        string
	RegisterPlugin  RegisterPluginType
	RegisterServers []string
	FailRetryModel  FailRetryModel
	BalanceModel    BalanceModel
	PoolSize        int
}

type ClientLoggerPlugin

type ClientLoggerPlugin struct {
}

func (*ClientLoggerPlugin) PostCall

func (p *ClientLoggerPlugin) PostCall(ctx context.Context, servicePath, serviceMethod string, args interface{}) error

type ClientPool

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

func NewRPCClient

func NewRPCClient(conf ClientConfig) (c *ClientPool, err error)

func (*ClientPool) Client

func (c *ClientPool) Client(auth ...string) *client.OneClient

type FailRetryModel

type FailRetryModel int

FailRetryModel 失败重试模式

const (
	// FailFast 如果调用失败,立即返回错误
	FailFast FailRetryModel = iota + 1
	// FailOver 如果调用失败,重试其他服务器
	FailOver
	// FailTry 如果调用失败,重试当前服务器
	FailTry
)

type RPCHeader

type RPCHeader struct {
}
func Header() *RPCHeader

func (*RPCHeader) Bool

func (h *RPCHeader) Bool(ctx context.Context, key string) (bool, error)

func (*RPCHeader) BoolDefault

func (h *RPCHeader) BoolDefault(ctx context.Context, key string, def bool) bool

func (*RPCHeader) Int

func (h *RPCHeader) Int(ctx context.Context, key string) (int, error)

func (*RPCHeader) Int32

func (h *RPCHeader) Int32(ctx context.Context, key string) (int32, error)

func (*RPCHeader) Int32Default

func (h *RPCHeader) Int32Default(ctx context.Context, key string, def int32) int32

func (*RPCHeader) Int64

func (h *RPCHeader) Int64(ctx context.Context, key string) (int64, error)

func (*RPCHeader) Int64Default

func (h *RPCHeader) Int64Default(ctx context.Context, key string, def int64) int64

func (*RPCHeader) IntDefault

func (h *RPCHeader) IntDefault(ctx context.Context, key string, def int) int

func (*RPCHeader) Set

func (h *RPCHeader) Set(ctx context.Context, header map[string]string) context.Context

func (*RPCHeader) Value

func (h *RPCHeader) Value(ctx context.Context, key string) string

type RegisterPluginType

type RegisterPluginType string
const (
	ETCD RegisterPluginType = "etcd"
	ZK   RegisterPluginType = "zookeeper"
	Con  RegisterPluginType = "consul"
)

type Server

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

func NewRPCServer

func NewRPCServer(conf ServerConfig, plugins ...server.Plugin) (rpc *Server, err error)

func (*Server) RegisterAuthFunc

func (s *Server) RegisterAuthFunc(authFunc AuthFunc)

RegisterAuthFunc 注册认证回调

func (*Server) Start

func (s *Server) Start()

Start 启动服务

type ServerConfig

type ServerConfig struct {
	ServerName      string
	Addr            string
	BasePath        string
	RegisterPlugin  RegisterPluginType
	RegisterServers []string
	Handle          interface{}
}

type ServerLoggerPlugin

type ServerLoggerPlugin struct {
}

func (*ServerLoggerPlugin) PostWriteResponse

func (p *ServerLoggerPlugin) PostWriteResponse(ctx context.Context, req *protocol.Message, res *protocol.Message, err error) error

func (*ServerLoggerPlugin) PreHandleRequest

func (p *ServerLoggerPlugin) PreHandleRequest(ctx context.Context, r *protocol.Message) error

Jump to

Keyboard shortcuts

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