liverpc

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 24 Imported by: 0

README

net/rpc/liverpc

项目简介

打通go和直播原有rpc通信的道路

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	Header *Header     `json:"header"`
	Body   interface{} `json:"body"`
	HTTP   interface{} `json:"http"`
}

Args .

type CallOption

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

CallOption ...

type Client

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

Client is a RPC client.

func NewClient

func NewClient(c *ClientConfig) *Client

NewClient new a RPC client with discovery.

func (*Client) Call

func (c *Client) Call(ctx context.Context, version int, serviceMethod string, in proto.Message, out proto.Message, opts ...CallOption) (err error)

Call call the service method, waits for it to complete, and returns its error status. client: {service} serviceMethod: {version}|{controller.method} httpURL: /room/v1/Room/room_init httpURL: /{service}/{version}/{controller}/{method}

func (*Client) CallRaw

func (c *Client) CallRaw(ctx context.Context, version int, serviceMethod string, in *Args, opts ...CallOption) (out *Reply, err error)

CallRaw call the service method, waits for it to complete, and returns reply its error status. this is can be use without protobuf client: {service} serviceMethod: {version}|{controller.method} httpURL: /room/v1/Room/room_init httpURL: /{service}/{version}/{controller}/{method}

func (*Client) Close

func (c *Client) Close()

Close handle client exit

type ClientConfig

type ClientConfig struct {
	AppID       string
	Group       string
	Timeout     xtime.Duration
	ConnTimeout xtime.Duration
	Addr        string // if addr is provided, it will use add, else, use discovery
}

ClientConfig client config.

type ClientConn

type ClientConn struct {
	Timeout     time.Duration
	DialTimeout time.Duration
	// contains filtered or unexported fields
}

ClientConn connect represent a real client connection to a rpc server

func Dial

func Dial(ctx context.Context, network, addr string, timeout time.Duration, connTimeout time.Duration) (*ClientConn, error)

Dial dial a rpc server

func (*ClientConn) Call

func (c *ClientConn) Call(ctx context.Context, version int, serviceMethod string, in, out proto.Message) (err error)

Call call the service method, waits for it to complete, and returns its error status. this is used with protobuf generated msg client: {service} serviceMethod: {version}|{controller.method} httpURL: /room/v1/Room/room_init httpURL: /{service}/{version}/{controller}/{method}

func (*ClientConn) CallRaw

func (c *ClientConn) CallRaw(ctx context.Context, version int, serviceMethod string, in *Args) (out *Reply, err error)

CallRaw call the service method, waits for it to complete, and returns reply its error status. this is can be use without protobuf client: {service} serviceMethod: {version}|{controller.method} httpURL: /room/v1/Room/room_init httpURL: /{service}/{version}/{controller}/{method}

func (*ClientConn) Close

func (c *ClientConn) Close() error

Close close the caller connection.

type GroupAddrs

type GroupAddrs map[string][]string

GroupAddrs a map struct storing addrs vary groups

type HTTP

type HTTP struct {
	IsHttps              int32             `protobuf:"varint,1,opt,name=is_https,json=isHttps,proto3" json:"is_https,omitempty"`
	Body                 string            `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
	Cookie               map[string]string `` /* 153-byte string literal not displayed */
	Header               map[string]string `` /* 153-byte string literal not displayed */
	Uri                  string            `protobuf:"bytes,5,opt,name=uri,proto3" json:"uri,omitempty"`
	Method               string            `protobuf:"bytes,6,opt,name=method,proto3" json:"method,omitempty"`
	Protocol             string            `protobuf:"bytes,7,opt,name=protocol,proto3" json:"protocol,omitempty"`
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

http is inside the protocol body {"body":..., "header":..., "http":...} this is used when a proxy forward a http request to a rpc request

func (*HTTP) Descriptor

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

func (*HTTP) GetBody

func (m *HTTP) GetBody() string

func (*HTTP) GetCookie

func (m *HTTP) GetCookie() map[string]string

func (*HTTP) GetHeader

func (m *HTTP) GetHeader() map[string]string

func (*HTTP) GetIsHttps

func (m *HTTP) GetIsHttps() int32

func (*HTTP) GetMethod

func (m *HTTP) GetMethod() string

func (*HTTP) GetProtocol

func (m *HTTP) GetProtocol() string

func (*HTTP) GetUri

func (m *HTTP) GetUri() string

func (*HTTP) ProtoMessage

func (*HTTP) ProtoMessage()

func (*HTTP) Reset

func (m *HTTP) Reset()

func (*HTTP) String

func (m *HTTP) String() string

func (*HTTP) XXX_DiscardUnknown

func (m *HTTP) XXX_DiscardUnknown()

func (*HTTP) XXX_Marshal

func (m *HTTP) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*HTTP) XXX_Merge

func (dst *HTTP) XXX_Merge(src proto.Message)

func (*HTTP) XXX_Size

func (m *HTTP) XXX_Size() int

func (*HTTP) XXX_Unmarshal

func (m *HTTP) XXX_Unmarshal(b []byte) error

type HTTPOption

type HTTPOption struct {
	HTTP *HTTP
}

HTTPOption contains HTTP for liverpc

type Header struct {
	// APP_NAME.xxxxx , when separated by dot,
	// the first part is always app_name, the rest is undefined
	Caller      string `protobuf:"bytes,1,opt,name=caller,proto3" json:"caller,omitempty"`
	Uid         int64  `protobuf:"varint,2,opt,name=uid,proto3" json:"uid,omitempty"`
	Platform    string `protobuf:"bytes,3,opt,name=platform,proto3" json:"platform,omitempty"`
	Src         string `protobuf:"bytes,4,opt,name=src,proto3" json:"src,omitempty"`
	TraceId     string `protobuf:"bytes,5,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"`
	UserIp      string `protobuf:"bytes,7,opt,name=user_ip,json=userIp,proto3" json:"user_ip,omitempty"`
	SourceGroup string `protobuf:"bytes,8,opt,name=source_group,json=sourceGroup,proto3" json:"source_group,omitempty"`
	Buvid       string `protobuf:"bytes,9,opt,name=buvid,proto3" json:"buvid,omitempty"`
	// session data, format is http query
	// such as access_token=abc&SESS_DATA=def
	Sessdata2            string   `protobuf:"bytes,10,opt,name=sessdata2,proto3" json:"sessdata2,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*Header) Descriptor

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

func (*Header) Get

func (m *Header) Get(key string) string

Get Implement tracer carrier interface

func (*Header) GetBuvid

func (m *Header) GetBuvid() string

func (*Header) GetCaller

func (m *Header) GetCaller() string

func (*Header) GetPlatform

func (m *Header) GetPlatform() string

func (*Header) GetSessdata2

func (m *Header) GetSessdata2() string

func (*Header) GetSourceGroup

func (m *Header) GetSourceGroup() string

func (*Header) GetSrc

func (m *Header) GetSrc() string

func (*Header) GetTraceId

func (m *Header) GetTraceId() string

func (*Header) GetUid

func (m *Header) GetUid() int64

func (*Header) GetUserIp

func (m *Header) GetUserIp() string

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) Reset

func (m *Header) Reset()

func (*Header) Set

func (m *Header) Set(key string, val string)

Set Implement tracer carrier interface

func (*Header) String

func (m *Header) String() string

func (*Header) XXX_DiscardUnknown

func (m *Header) XXX_DiscardUnknown()

func (*Header) XXX_Marshal

func (m *Header) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Header) XXX_Merge

func (dst *Header) XXX_Merge(src proto.Message)

func (*Header) XXX_Size

func (m *Header) XXX_Size() int

func (*Header) XXX_Unmarshal

func (m *Header) XXX_Unmarshal(b []byte) error

type HeaderOption

type HeaderOption struct {
	Header *Header
}

HeaderOption contains Header for liverpc

type Key

type Key int

Key is ContextKey

const (

	// KeyHeader use this in context to pass rpc header field
	// Depreated 请使用HeaderOption来传递Header
	KeyHeader Key
	// KeyTimeout deprecated
	// Depreated 请使用HTTPOption来传递HTTP
	KeyTimeout
)

type Reply

type Reply struct {
	Code    int             `json:"code"`
	Message string          `json:"msg"`
	Data    json.RawMessage `json:"data"`
}

Reply .

type TimeoutOption

type TimeoutOption struct {
	DialTimeout time.Duration
	Timeout     time.Duration
}

TimeoutOption is timeout for a specific call

Directories

Path Synopsis
Package liverpc .
Package liverpc .

Jump to

Keyboard shortcuts

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