Documentation ¶
Index ¶
- Constants
- Variables
- func NewJsonRpcErr(code int, message string, data interface{}) error
- type JsonRpcErr
- type JsonRpcReq
- type JsonRpcRes
- type Msg
- type NexusConn
- func (nc *NexusConn) Close()
- func (nc *NexusConn) Closed() bool
- func (nc *NexusConn) Exec(method string, params interface{}) (result interface{}, err error)
- func (nc *NexusConn) ExecNoWait(method string, params interface{}) (id uint64, rch chan *JsonRpcRes, err error)
- func (nc *NexusConn) GetContext() context.Context
- func (nc *NexusConn) Id() string
- func (nc *NexusConn) Lock(lock string) (bool, error)
- func (nc *NexusConn) Login(user string, pass string) (interface{}, error)
- func (nc *NexusConn) NodeList(limit int, skip int) ([]NodeInfo, error)
- func (nc *NexusConn) Ping(timeout time.Duration) (err error)
- func (nc *NexusConn) PipeCreate(opts ...*PipeOpts) (*Pipe, error)
- func (nc *NexusConn) PipeOpen(pipeId string) (*Pipe, error)
- func (nc *NexusConn) Reload() (interface{}, error)
- func (nc *NexusConn) SessionKick(connId string) (interface{}, error)
- func (nc *NexusConn) SessionList(prefix string, limit int, skip int) ([]UserSessions, error)
- func (nc *NexusConn) SessionReload(connId string) (interface{}, error)
- func (nc *NexusConn) TaskList(prefix string, limit int, skip int) (*TaskList, error)
- func (nc *NexusConn) TaskPull(prefix string, timeout time.Duration) (*Task, error)
- func (nc *NexusConn) TaskPush(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (interface{}, error)
- func (nc *NexusConn) TaskPushCh(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (<-chan interface{}, <-chan error)
- func (nc *NexusConn) TopicPublish(topic string, msg interface{}) (interface{}, error)
- func (nc *NexusConn) TopicSubscribe(pipe *Pipe, topic string) (interface{}, error)
- func (nc *NexusConn) TopicUnsubscribe(pipe *Pipe, topic string) (interface{}, error)
- func (nc *NexusConn) Unlock(lock string) (bool, error)
- func (nc *NexusConn) UserAddTemplate(user, template string) (interface{}, error)
- func (nc *NexusConn) UserCreate(user, pass string) (interface{}, error)
- func (nc *NexusConn) UserDelTags(user string, prefix string, tags []string) (interface{}, error)
- func (nc *NexusConn) UserDelTemplate(user, template string) (interface{}, error)
- func (nc *NexusConn) UserDelete(user string) (interface{}, error)
- func (nc *NexusConn) UserList(prefix string, limit int, skip int) ([]UserInfo, error)
- func (nc *NexusConn) UserListTemplate(user string) (interface{}, error)
- func (nc *NexusConn) UserSetPass(user string, pass string) (interface{}, error)
- func (nc *NexusConn) UserSetTags(user string, prefix string, tags map[string]interface{}) (interface{}, error)
- type NodeInfo
- type Pipe
- func (p *Pipe) Close() (interface{}, error)
- func (p *Pipe) Id() string
- func (p *Pipe) Listen(ch chan *Msg) chan *Msg
- func (p *Pipe) Read(max int, timeout time.Duration) (*PipeData, error)
- func (p *Pipe) TopicListen(ch chan *TopicMsg) chan *TopicMsg
- func (p *Pipe) TopicRead(max int, timeout time.Duration) (*TopicData, error)
- func (p *Pipe) Write(msg interface{}) (interface{}, error)
- type PipeData
- type PipeOpts
- type SessionInfo
- type Task
- type TaskList
- type TaskOpts
- type TopicData
- type TopicMsg
- type UserInfo
- type UserSessions
Constants ¶
const ( ErrParse = -32700 ErrInvalidRequest = -32600 ErrMethodNotFound = -32601 ErrInvalidParams = -32602 ErrInternal = -32603 ErrTimeout = -32000 ErrCancel = -32001 ErrInvalidTask = -32002 ErrInvalidPipe = -32003 ErrInvalidUser = -32004 ErrUserExists = -32005 ErrPermissionDenied = -32010 ErrTtlExpired = -32011 )
Variables ¶
var ErrStr = map[int]string{ ErrParse: "Parse error", ErrInvalidRequest: "Invalid request", ErrMethodNotFound: "Method not found", ErrInvalidParams: "Invalid params", ErrInternal: "Internal error", ErrTimeout: "Timeout", ErrCancel: "Cancel", ErrInvalidTask: "Invalid task", ErrInvalidPipe: "Invalid pipe", ErrInvalidUser: "Invalid user", ErrUserExists: "User already exists", ErrPermissionDenied: "Permission denied", ErrTtlExpired: "TTL expired", }
Functions ¶
func NewJsonRpcErr ¶
NewJsonRpcErr creates new JSON-RPC error.
code is the JSON-RPC error code. message is optional in case of well known error code (negative values). data is an optional extra info object.
Types ¶
type JsonRpcErr ¶
type JsonRpcErr struct { Cod int `json:"code"` Mess string `json:"message"` Dat interface{} `json:"data,omitempty"` }
func (*JsonRpcErr) Code ¶
func (e *JsonRpcErr) Code() int
func (*JsonRpcErr) Data ¶
func (e *JsonRpcErr) Data() interface{}
func (*JsonRpcErr) Error ¶
func (e *JsonRpcErr) Error() string
type JsonRpcReq ¶
type JsonRpcRes ¶
type JsonRpcRes struct { Jsonrpc string `json:"jsonrpc"` Id uint64 `json:"id,omitempty"` Result interface{} `json:"result,omitempty"` Error *JsonRpcErr `json:"error,omitempty"` }
type Msg ¶
type Msg struct { Count int64 // Message counter (unique and correlative) Msg interface{} // Pipe message }
Msg represents a pipe single message
type NexusConn ¶
type NexusConn struct {
// contains filtered or unexported fields
}
NexusConn represents the Nexus connection.
func NewNexusConn ¶
NewNexusConn creates new nexus connection from net.conn
func (*NexusConn) ExecNoWait ¶
func (nc *NexusConn) ExecNoWait(method string, params interface{}) (id uint64, rch chan *JsonRpcRes, err error)
ExecNoWait is a low level JSON-RPC call function, it don't wait response from server.
func (*NexusConn) GetContext ¶
GetContext returns internal connection context.
func (*NexusConn) Login ¶
Login attempts to login using user and pass. Returns the response object from Nexus or error.
func (*NexusConn) NodeList ¶
Nodes returns info of the nodes state Returns a list of NodeInfo structs or an error
func (*NexusConn) Ping ¶
Ping pings Nexus server, timeout is the max time waiting for server response, after that ErrTimeout is returned.
func (*NexusConn) PipeCreate ¶
PipeCreate creates a new pipe. Returns the new pipe object or error.
func (*NexusConn) PipeOpen ¶
PipeOpen Creates a new pipe from pipe identification string. Returns the new pipe object or error.
func (*NexusConn) Reload ¶
Reload forces the node owner of the client connection to reload its info (tags) Returns the response object from Nexus or error.
func (*NexusConn) SessionKick ¶
SessionKick forces the node owner of the client connection to close it Returns the response object from Nexus or error.
func (*NexusConn) SessionList ¶
Sessions returns info of the users sessions Returns a list of SessionInfo structs or an error
func (*NexusConn) SessionReload ¶
SessionReload forces the node owner of the client connection to reload its info (tags) Returns the response object from Nexus or error.
func (*NexusConn) TaskList ¶
TaskList returns how many push/pulls are happening on a path prefix is the method prefix we want pull Ex. "test.fibonacci" Returns a TaskList or error.
func (*NexusConn) TaskPull ¶
TaskPull pulls a task from Nexus cloud. prefix is the method prefix we want pull Ex. "test.fibonacci" timeout is the maximum time waiting for a task. Returns a new incomming Task or error.
func (*NexusConn) TaskPush ¶
func (nc *NexusConn) TaskPush(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (interface{}, error)
TaskPush pushes a task to Nexus cloud. method is the method path Ex. "test.fibonacci.fib" params is the method params object. timeout is the maximum time waiting for response, 0 = no timeout. options (see TaskOpts struct) Returns the task result or error.
func (*NexusConn) TaskPushCh ¶
func (nc *NexusConn) TaskPushCh(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (<-chan interface{}, <-chan error)
TaskPushCh pushes a task to Nexus cloud. method is the method path Ex. "test.fibonacci.fib" params is the method params object. timeout is the maximum time waiting for response, 0 = no timeout. options (see TaskOpts struct) Returns two channels (one for result of interface{} type and one for error of error type).
func (*NexusConn) TopicPublish ¶
TopicPublish publishes message to a topic. Returns the response object from Nexus or error.
func (*NexusConn) TopicSubscribe ¶
TopicSubscribe subscribes a pipe to a topic. Returns the response object from Nexus or error.
func (*NexusConn) TopicUnsubscribe ¶
TopicUnsubscribe unsubscribes a pipe from a topic. Returns the response object from Nexus or error.
func (*NexusConn) UserAddTemplate ¶
UserAddTemplate adds a new template to the user. Returns the response object from Nexus or error.
func (*NexusConn) UserCreate ¶
UserCreate creates new user in Nexus user's table. Returns the response object from Nexus or error.
func (*NexusConn) UserDelTags ¶
UserDelTags remove tags from user's prefix. Returns the response object from Nexus or error.
func (*NexusConn) UserDelTemplate ¶
UserDelTemplate removes a template from the user. Returns the response object from Nexus or error.
func (*NexusConn) UserDelete ¶
UserDelete removes user from Nexus user's table. Returns the response object from Nexus or error.
func (*NexusConn) UserList ¶
UserList lists users from Nexus user's table. Returns a list of UserInfo or error.
func (*NexusConn) UserListTemplate ¶
UserListTemplate returns the templates from the user. Returns the response object from Nexus or error.
func (*NexusConn) UserSetPass ¶
UserSetPass sets new user password. Returns the response object from Nexus or error.
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe represents a pipe. Pipes can only be read from the connection that created them and can be written from any conection.
func (*Pipe) Listen ¶
Listen returns a pipe reader channel. ch is the channel used and returned by Listen, if ch is nil Listen creates a new unbuffered channel. channel is closed when pipe is closed or error happens.
func (*Pipe) TopicListen ¶
TopicListen returns a pipe topic reader channel. ch is the channel used and returned by Listen, if ch is nil Listen creates a new unbuffered channel. channel is closed when pipe is closed or error happens.
type PipeData ¶
type PipeData struct { Msgs []*Msg // Messages Waiting int // Number of messages waiting in Nexus server since last read Drops int // Number of messages dropped (pipe overflows) since last read }
PipeData represents a pipe messages group obtained in read ops.
type PipeOpts ¶
type PipeOpts struct {
Length int // Pipe buffer capacity
}
PipeOpts represents pipe creation options
type SessionInfo ¶
type Task ¶
type Task struct { Path string Method string Params interface{} Prio int Detach bool User string Tags map[string]interface{} // contains filtered or unexported fields }
Task represents a task pushed to Nexus.
func (*Task) SendError ¶
SendError closes Task with error. code is the JSON-RPC error code. message is optional in case of well known error code (negative values). data is an optional extra info object. Returns the response object from Nexus or error.
func (*Task) SendResult ¶
SendResult closes Task with result. Returns the response object from Nexus or error.
type TaskOpts ¶
type TaskOpts struct { // Task priority default 0 (Set negative value for lower priority) Priority int // Task ttl default 5 Ttl int // Task detach. If true, task is detached from creating session. // If task is detached and creating session deads, task is not removed from tasks queue. Detach bool }
TaskOpts represents task push options.
type TopicData ¶
type TopicData struct { Msgs []*TopicMsg // Messages Waiting int // Number of messages waiting in Nexus server since last read Drops int // Number of messages dropped (pipe overflows) since last read }
TopicData represents a topic messages group obtained in read ops.
type TopicMsg ¶
type TopicMsg struct { Topic string // Topic the message was published to Count int64 // Message counter (unique and correlative) Msg interface{} // The message itself }
TopicMsg represents a single topic message
type UserSessions ¶
type UserSessions struct { User string `json:"user"` Sessions []SessionInfo `json:"sessions"` N int `json:"n"` }