jsonrpc

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_JSONRPC_ID = 0x7FFFFFFF
	VERSION        = "2.0"
)
View Source
const (
	// Errors defined in the JSON-RPC spec. See
	// http://www.jsonrpc.org/specification#error_object.
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
)
View Source
const (
	DefaultMaxSleepTime      = 1 * time.Second // accept中间最大sleep interval
	DefaultHTTPRspBufferSize = 1024
	PathPrefix               = byte('/')
)

Variables

View Source
var (
	Version = "2.0"
)

Functions

This section is empty.

Types

type CodecData

type CodecData struct {
	ID     int64
	Method string
	Args   interface{}
	Error  string
}

type Error

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

rsponse Error

func NewError

func NewError(code int, message string) *Error

func (*Error) Error

func (e *Error) Error() string

type HTTPClient

type HTTPClient struct {
	ID int64
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(opt *HTTPOptions) *HTTPClient

func (*HTTPClient) Call

func (c *HTTPClient) Call(ctx context.Context, service registry.ServiceURL, req Request, rsp interface{}) error

func (*HTTPClient) Do

func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte) ([]byte, error)

!!The high level of complexity and the likelihood that the fasthttp client has not been extensively used in production means that you would need to expect a very large benefit to justify the adoption of fasthttp today. from: http://big-elephants.com/2016-12/fasthttp-client/

func (*HTTPClient) NewRequest

func (c *HTTPClient) NewRequest(conf registry.ServiceConfig, method string, args interface{}) Request

type HTTPOptions

type HTTPOptions struct {
	HandshakeTimeout time.Duration
	HTTPTimeout      time.Duration
}

type Handler

type Handler interface {
	Service() string // Service Interface
	Version() string
}

type Option

type Option func(*Options)

func ConfList

func ConfList(confList []registry.ServerConfig) Option

func Registry

func Registry(r registry.Registry) Option

Registry used for discovery

func ServiceConfList

func ServiceConfList(confList []registry.ServiceConfig) Option

type Options

type Options struct {
	Registry        registry.Registry
	ConfList        []registry.ServerConfig
	ServiceConfList []registry.ServiceConfig
	Timeout         time.Duration
}

type Request

type Request struct {
	ID int64
	// contains filtered or unexported fields
}

func (*Request) ServiceConfig

func (r *Request) ServiceConfig() registry.ServiceConfigIf

type Server

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) Handle

func (s *Server) Handle(h Handler) error

func (*Server) Options

func (s *Server) Options() Options

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop()

type ServerCodec

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

func (*ServerCodec) ReadBody

func (c *ServerCodec) ReadBody(x interface{}) error

func (*ServerCodec) ReadHeader

func (c *ServerCodec) ReadHeader(header map[string]string, body []byte) error

func (*ServerCodec) Write

func (c *ServerCodec) Write(errMsg string, x interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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