wrpc_go

package module
v0.0.0-...-d5dbc52 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

wrpc-go

Documentation

Index

Constants

View Source
const (
	EncodeType        = "encode-type"
	ConsistentHashKey = "consistenthash"
)

Variables

View Source
var (
	ErrPageNotFound   = fmt.Errorf("404 page not found")
	ErrMethodNotFound = fmt.Errorf("method not found")
)
View Source
var (
	ErrServerIsRunning = fmt.Errorf("rpc: server is running")
	ErrServerIsClosed  = fmt.Errorf("rpc: server is closed")
)
View Source
var ErrConnectNotFound = fmt.Errorf("connect not found")
View Source
var File_requset_proto protoreflect.FileDescriptor
View Source
var File_response_proto protoreflect.FileDescriptor

Functions

func GetRequestTimeout

func GetRequestTimeout() time.Duration

func NewOutgoingContext

func NewOutgoingContext(ctx context.Context, meta Meta) context.Context

func RegisterEncoder

func RegisterEncoder(enc Encoder)

Types

type App

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

func NewApp

func NewApp(opts ...AppOption) *App

func (*App) AddServer

func (app *App) AddServer(server Server)

func (*App) Run

func (app *App) Run() error

type AppOption

type AppOption interface {
	// contains filtered or unexported methods
}

func WithRegister

func WithRegister(register register.Register) AppOption

func WithServer

func WithServer(server Server) AppOption

type AppOptionFunc

type AppOptionFunc func(app *App)

type Client

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

func NewClient

func NewClient(name string, opts ...ClientOption) *Client

func (*Client) GetAllEndpoints

func (client *Client) GetAllEndpoints() []string

func (*Client) Invoke

func (client *Client) Invoke(ctx context.Context, encName, addr, method string, in []byte, opt ...map[string]string) ([]byte, error)

type ClientConfig

type ClientConfig struct {
	RequestTimeout time.Duration `yaml:"request-timeout"`
	ReadBufferSize int32         `yaml:"read-buffer-size"`
	Thread         int           `yaml:"thread"`
	MaxIdleTime    time.Duration `yaml:"max-idle-time"`
	EncodeType     string        `yaml:"encode-type"`
	ReTry          int           `yaml:"retry"`
}

func GetClientConfig

func GetClientConfig() *ClientConfig

type ClientOption

type ClientOption func(opt *ClientOptions)

func WithClientOptionAddr

func WithClientOptionAddr(addr string) ClientOption

func WithClientOptionEncodeType

func WithClientOptionEncodeType(encodeType string) ClientOption

func WithClientOptionMaxConn

func WithClientOptionMaxConn(max int) ClientOption

func WithClientOptionsDiscover

func WithClientOptionsDiscover(discover discovery.Discover) ClientOption

type ClientOptions

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

type Config

type Config struct {
	BaseDir        string                    `yaml:"base-dir"`
	LogDir         string                    `yaml:"log-dir"`
	DiscoverConfig *discovery.DiscoverConfig `yaml:"discover"`
	RegisterConfig *register.RegisterConfig  `yaml:"register"`
	ServerConfigs  []*ServerConfig           `yaml:"server-config"`
	ClientConfig   *ClientConfig             `yaml:"client-config"`
}

func GetConfig

func GetConfig() *Config

type Dispatcher

type Dispatcher func(ctx context.Context, impl interface{}, req *Request, enc Encoder) ([]byte, error)

type Encoder

type Encoder interface {
	Encode(v interface{}) ([]byte, error)
	Decode(bs []byte, addr interface{}) error
	Name() string
}

func GetEncoder

func GetEncoder(name string) Encoder

type HttpServer

type HttpServer struct {
	*http.Server
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(name string, handler http.Handler, opts ...ServerOption) *HttpServer

func (*HttpServer) Name

func (srv *HttpServer) Name() string

func (*HttpServer) Start

func (srv *HttpServer) Start() error

func (*HttpServer) Stop

func (srv *HttpServer) Stop(ctx context.Context) error

func (*HttpServer) String

func (srv *HttpServer) String() string

func (*HttpServer) Target

func (srv *HttpServer) Target() *register.Target

type Meta

type Meta map[string]string

func FromOutgoingContext

func FromOutgoingContext(ctx context.Context) (Meta, bool)

func (Meta) Get

func (m Meta) Get(k string) string

func (Meta) Set

func (m Meta) Set(k, v string)

type Protocol

type Protocol interface {
	PacketRequest(request *Request) ([]byte, error)
	UnPacketRequest(body []byte) (*Request, error)

	PacketResponse(response *Response) ([]byte, error)
	UnPacketResponse(body []byte) (*Response, error)

	Name() string
}

type Request

type Request struct {
	RequestId int64             `protobuf:"varint,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
	Method    string            `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"`
	Meta      map[string]string `` /* 149-byte string literal not displayed */
	Body      []byte            `protobuf:"bytes,4,opt,name=body,proto3" json:"body,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

func (*Request) Descriptor() ([]byte, []int)

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetBody

func (x *Request) GetBody() []byte

func (*Request) GetMeta

func (x *Request) GetMeta() map[string]string

func (*Request) GetMethod

func (x *Request) GetMethod() string

func (*Request) GetRequestId

func (x *Request) GetRequestId() int64

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	RequestId  int64             `protobuf:"varint,1,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"`
	Meta       map[string]string `` /* 149-byte string literal not displayed */
	Body       []byte            `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"`
	Code       int32             `protobuf:"varint,4,opt,name=code,proto3" json:"code,omitempty"`
	CodeStatus string            `protobuf:"bytes,5,opt,name=code_status,json=codeStatus,proto3" json:"code_status,omitempty"`
	// contains filtered or unexported fields
}

func GetResponse

func GetResponse(req *Request, bs []byte, err error) *Response

func (*Response) Descriptor deprecated

func (*Response) Descriptor() ([]byte, []int)

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetBody

func (x *Response) GetBody() []byte

func (*Response) GetCode

func (x *Response) GetCode() int32

func (*Response) GetCodeStatus

func (x *Response) GetCodeStatus() string

func (*Response) GetMeta

func (x *Response) GetMeta() map[string]string

func (*Response) GetRequestId

func (x *Response) GetRequestId() int64

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type Server

type Server interface {
	Start() error
	Stop(ctx context.Context) error
	Name() string
	Target() *register.Target
}

type ServerConfig

type ServerConfig struct {
	Name           string `yaml:"name"`
	IP             string `yaml:"ip"`
	Port           string `yaml:"port"`
	MaxInvoke      int32  `yaml:"max-invoke"`
	ReadBufferSize int32  `yaml:"read-buffer-size"`
}

func GetServerConfig

func GetServerConfig(name string) *ServerConfig

type ServerOption

type ServerOption func(opt *ServerOptions)

func WithServerOptionAddr

func WithServerOptionAddr(addr string) ServerOption

func WithServerOptionReadSize

func WithServerOptionReadSize(size int32) ServerOption

type ServerOptions

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

type TcpServer

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

func NewRPCServer

func NewRPCServer(name string, impl interface{}, dispatcher Dispatcher, opts ...ServerOption) *TcpServer

func (*TcpServer) Name

func (srv *TcpServer) Name() string

func (*TcpServer) Start

func (srv *TcpServer) Start() error

func (*TcpServer) Stop

func (srv *TcpServer) Stop(ctx context.Context) error

func (*TcpServer) Target

func (srv *TcpServer) Target() *register.Target

Directories

Path Synopsis
example
helloworld command
internal
util

Jump to

Keyboard shortcuts

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