rpc

package
v0.0.0-...-b4fed4d Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TargetAddress    = "rpc_target_address"
	RequestTimeoutMs = "rpc_request_timeout"
)
View Source
const (
	DefaultRequestTimeoutMs = 3000
)
View Source
const ServiceName = "rpc"

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback interface {
	// AddBeforeInvoke is add BeforeInvoke func
	AddBeforeInvoke(CallbackFunc)
	// AddAfterInvoke is add AfterInvoke func
	AddAfterInvoke(CallbackFunc)

	// BeforeInvoke is used to invoke beforeInvoke callbacks
	BeforeInvoke(*RPCRequest) (*RPCRequest, error)
	// AfterInvoke is used to invoke afterInvoke callbacks
	AfterInvoke(*RPCResponse) (*RPCResponse, error)
}

Callback is interface for before invoke or after invoke

type CallbackFunc

type CallbackFunc struct {
	Name   string          `json:"name"`
	Config json.RawMessage `json:"config"`
}

CallbackFunc is Callback implement

type Channel

type Channel interface {
	Do(*RPCRequest) (*RPCResponse, error)
}

Channel is handle RPCRequest to RPCResponse

type Factory

type Factory struct {
	Name string
	Fm   FactoryMethod
}

Factory is NewRpcFactory implement

func NewRpcFactory

func NewRpcFactory(name string, fm FactoryMethod) *Factory

NewRpcFactory is rpc create factory entrance

type FactoryMethod

type FactoryMethod func() Invoker

type Invoker

type Invoker interface {
	Init(config RpcConfig) error
	Invoke(ctx context.Context, req *RPCRequest) (*RPCResponse, error)
}

Invoker is interface for init rpc config or invoke rpc request

type RPCHeader

type RPCHeader map[string][]string

RPCHeader is storage header info

func (RPCHeader) Get

func (r RPCHeader) Get(key string) string

Get is get RPCHeader info

func (RPCHeader) Range

func (r RPCHeader) Range(f func(key string, value string) bool)

Range is handle RPCHeader info

type RPCRequest

type RPCRequest struct {
	// context
	Ctx context.Context
	// request id
	Id          string
	Timeout     int32
	Method      string
	ContentType string
	Header      RPCHeader
	Data        []byte
}

RPCRequest is request info

type RPCResponse

type RPCResponse struct {
	Ctx         context.Context
	Header      RPCHeader
	ContentType string
	Data        []byte
	Success     bool
	Error       error
}

RPCResponse is response info

type Registry

type Registry interface {
	Register(fs ...*Factory)
	Create(name string) (Invoker, error)
}

Registry is interface for registry

func NewRegistry

func NewRegistry(info *info.RuntimeInfo) Registry

NewRegistry is init rpcRegistry

type RpcConfig

type RpcConfig struct {
	Config json.RawMessage
}

Directories

Path Synopsis
invoker

Jump to

Keyboard shortcuts

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