Documentation ¶
Index ¶
- Constants
- Variables
- type BaseMessage
- type BuildInError
- type CancelParams
- type CloserReader
- type CloserWriter
- type Conn
- type FnMessageReaderWriter
- type JsonRpcWebsocket
- type JsonRpcWebsocketServer
- type JsonRpcWebsocketServerConfig
- type MessageReaderWriter
- type MethodInfo
- type NotificationMessage
- type ProgressParams
- type ReaderWriter
- type RequestMessage
- type ResponseError
- type ResponseMessage
- type Server
- type Session
- func (s *Session) Client() string
- func (s *Session) Close() error
- func (s *Session) Closed() bool
- func (s *Session) Context() *core.Context
- func (s *Session) IsShuttingDown() bool
- func (s *Session) Notify(notif NotificationMessage) error
- func (s *Session) SendRequest(req RequestMessage) error
- func (s *Session) SetClosedCallbackFn(fn func(session *Session))
- func (s *Session) SetContextOnce(ctx *core.Context) error
- func (s *Session) SetShutdownCallbackFn(fn func(session *Session))
- func (s *Session) Start()
- type SessionCreationCallbackFn
Constants ¶
View Source
const ( JSONRPC_VERSION = "2.0" MAX_PARAMS_LOGGING_SIZE = 3000 )
View Source
const ( JSON_RPC_SERVER_LOG_SRC = "json-rpc" DEFAULT_MAX_IP_WS_CONNS = 3 DEFAULT_MAX_IP_WS_CONNS_IF_BEHIND_PROXY = 10_000 )
View Source
const (
CANCEL_REQUEST_METHOD = "$/cancelRequest"
)
View Source
const (
CONTENT_LENGTH_HEADER = "Content-Length: "
)
View Source
const ContentModifiedCode = -32801
View Source
const InternalErrorCode = -32603
View Source
const InvalidParamsCode = -32602
View Source
const InvalidRequestCode = -32600
View Source
const MethodNotFoundCode = -32601
View Source
const ParseErrorCode = -32700
View Source
const RequestCancelledCode = -32800
View Source
const ServerNotInitializedCode = -32002
View Source
const UnknownErrorCodeCode = -32001
Variables ¶
View Source
var ( DEFAULT_METHOD_RATE_LIMITS = []int{5, 20, 80} //rate limits for a single method DEFAULT_MESSAGE_RATE_LIMITS = [2]int{70, 200} )
View Source
var ( ErrRateLimitedMethod = errors.New("rate limited method") ErrRateLimited = errors.New("rate limited") ErrAlreadyShuttingDown = errors.New("session is already shutting down") )
View Source
var ContentModified = BuildInError{ Code: ContentModifiedCode, Message: "ContentModified", }
View Source
var (
ErrOnly127001AllowedIfBehindProxy = errors.New("only connections from the same host (127.0.0.1) are allowed")
)
View Source
var InternalError = BuildInError{ Code: InternalErrorCode, Message: "InternalError", }
View Source
var InvalidParams = BuildInError{ Code: InvalidParamsCode, Message: "InvalidParams", }
View Source
var InvalidRequest = BuildInError{ Code: InvalidRequestCode, Message: "InvalidRequest", }
View Source
var MethodNotFound = BuildInError{ Code: MethodNotFoundCode, Message: "MethodNotFound", }
View Source
var ParseError = BuildInError{ Code: ParseErrorCode, Message: "ParseError", }
View Source
var RequestCancelled = BuildInError{ Code: RequestCancelledCode, Message: "RequestCancelled", }
View Source
var ServerNotInitialized = BuildInError{ Code: ServerNotInitializedCode, Message: "ServerNotInitialized", }
View Source
var UnknownErrorCode = BuildInError{ Code: UnknownErrorCodeCode, Message: "UnknownErrorCode", }
Functions ¶
This section is empty.
Types ¶
type BaseMessage ¶
type BaseMessage struct {
Jsonrpc string `json:"jsonrpc"`
}
type BuildInError ¶
type BuildInError = ResponseError
type CancelParams ¶
type CancelParams struct {
ID interface{} `json:"id"` // the method id should be canceled
}
type CloserReader ¶
func NewFakeCloserReader ¶
func NewFakeCloserReader(r io.Reader) CloserReader
type CloserWriter ¶
func NewFakeCloserWriter ¶
func NewFakeCloserWriter(w io.Writer) CloserWriter
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
The connection of rpc, not limited to net.Conn
func NewConn ¶
func NewConn(reader CloserReader, writer CloserWriter) *Conn
type FnMessageReaderWriter ¶
type FnMessageReaderWriter struct { ReadMessageFn func() (msg []byte, err error) WriteMessageFn func(msg []byte) error CloseFn func() error ClientFn func() string }
func (FnMessageReaderWriter) Client ¶
func (rw FnMessageReaderWriter) Client() string
func (FnMessageReaderWriter) Close ¶
func (rw FnMessageReaderWriter) Close() error
func (FnMessageReaderWriter) ReadMessage ¶
func (rw FnMessageReaderWriter) ReadMessage() (msg []byte, err error)
func (FnMessageReaderWriter) WriteMessage ¶
func (rw FnMessageReaderWriter) WriteMessage(msg []byte) error
type JsonRpcWebsocket ¶
type JsonRpcWebsocket struct {
// contains filtered or unexported fields
}
func NewJsonRpcWebsocket ¶
func NewJsonRpcWebsocket(conn *ws_ns.WebsocketConnection, logger zerolog.Logger) *JsonRpcWebsocket
func (*JsonRpcWebsocket) Client ¶
func (s *JsonRpcWebsocket) Client() string
func (*JsonRpcWebsocket) Close ¶
func (s *JsonRpcWebsocket) Close() error
func (*JsonRpcWebsocket) ReadMessage ¶
func (s *JsonRpcWebsocket) ReadMessage() ([]byte, error)
func (*JsonRpcWebsocket) WriteMessage ¶
func (s *JsonRpcWebsocket) WriteMessage(msg []byte) error
type JsonRpcWebsocketServer ¶
type JsonRpcWebsocketServer struct {
// contains filtered or unexported fields
}
func NewJsonRpcWebsocketServer ¶
func NewJsonRpcWebsocketServer(ctx *core.Context, config JsonRpcWebsocketServerConfig) (*JsonRpcWebsocketServer, error)
func (*JsonRpcWebsocketServer) HandleNew ¶
func (server *JsonRpcWebsocketServer) HandleNew(httpRespWriter http.ResponseWriter, httpReq *http.Request)
func (*JsonRpcWebsocketServer) Logger ¶
func (server *JsonRpcWebsocketServer) Logger() *zerolog.Logger
type JsonRpcWebsocketServerConfig ¶
type JsonRpcWebsocketServerConfig struct { Addr string RpcServer *Server //defaults to DEFAULT_MAX_IP_WS_CONNS MaxWebsocketPerIp int //if true only connections from localhost are allowed and //the effective value of MaxWebsocketPerIp is set to DEFAULT_MAX_IP_WS_CONNS_IF_BEHIND_PROXY. BehindCloudProxy bool }
type MessageReaderWriter ¶
type MessageReaderWriter interface { //ReadMessage reads an entire message and returns it, the returned bytes should not be modified by the caller. ReadMessage() (msg []byte, err error) //WriteMessage writes an entire message and returns it, the written bytes should not modified by the implementation. WriteMessage(msg []byte) error io.Closer Client() string }
type MethodInfo ¶
type MethodInfo struct { Name string NewRequest func() interface{} Handler func(ctx context.Context, req interface{}) (interface{}, error) SensitiveData bool AvoidLogging bool // List of the maximum number of calls allowed during windows with increasing durations (1s, 10s, and 100s). // Example: [10, 50, 200] means at most 10 calls in 1s, 50 calls in 50s and 200 calls in 100s. RateLimits []int }
func CancelRequest ¶
func CancelRequest() MethodInfo
type NotificationMessage ¶
type NotificationMessage struct { BaseMessage Method string `json:"method"` // starts with "/$", server build-in methods. Params json.RawMessage `json:"params"` // params, is some struct or slice }
type ProgressParams ¶
type ProgressParams struct { Token interface{} `json:"token"` // int or string /** * The progress data. */ Value interface{} `json:"value"` }
type RequestMessage ¶
type RequestMessage struct { BaseMessage ID interface{} `json:"id"` // may be int or string Method string `json:"method"` Params json.RawMessage `json:"params"` // params, is some struct or slice }
type ResponseError ¶
type ResponseError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
func (ResponseError) Error ¶
func (r ResponseError) Error() string
type ResponseMessage ¶
type ResponseMessage struct { BaseMessage ID interface{} `json:"id"` // may be int or string Result interface{} `json:"result"` Error *ResponseError `json:"error"` }
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ConnComeIn ¶
func (server *Server) ConnComeIn(conn ReaderWriter)
func (*Server) MsgConnComeIn ¶
func (server *Server) MsgConnComeIn(conn MessageReaderWriter, onCreatedSession func(session *Session))
func (*Server) RegisterMethod ¶
func (server *Server) RegisterMethod(m MethodInfo)
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func GetSession ¶
func (*Session) IsShuttingDown ¶
func (*Session) Notify ¶
func (s *Session) Notify(notif NotificationMessage) error
SendRequest sends a notification to the client, NotificationMessage.BaseMessage is set by the callee.
func (*Session) SendRequest ¶
func (s *Session) SendRequest(req RequestMessage) error
SendRequest sends a request to the client, RequestMessage.ID & RequestMessage.BaseMessage are set by the callee.
func (*Session) SetClosedCallbackFn ¶
func (*Session) SetShutdownCallbackFn ¶
Click to show internal directories.
Click to hide internal directories.