Documentation
¶
Index ¶
- Constants
- Variables
- func NewJsonRpcErr(code int, message string, data interface{}) error
- type CountOpts
- type JsonRpcErr
- type JsonRpcReq
- type JsonRpcRes
- type ListOpts
- type LockInfo
- 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) (interface{}, error)
- func (nc *NexusConn) LockCount(prefix string, opts ...*CountOpts) (interface{}, error)
- func (nc *NexusConn) LockList(prefix string, limit int, skip int, opts ...*ListOpts) ([]LockInfo, error)
- func (nc *NexusConn) Login(user string, pass string) (interface{}, error)
- func (nc *NexusConn) Node() (*NodeInfo, 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) SessionCount(prefix string, opts ...*CountOpts) (interface{}, error)
- func (nc *NexusConn) SessionKick(connId string) (interface{}, error)
- func (nc *NexusConn) SessionList(prefix string, limit int, skip int, opts ...*ListOpts) ([]UserSessions, error)
- func (nc *NexusConn) SessionReload(connId string) (interface{}, error)
- func (nc *NexusConn) SetInactivityTimeout(timeout time.Duration) (err error)
- func (nc *NexusConn) TaskCount(prefix string, opts ...*CountOpts) (interface{}, error)
- func (nc *NexusConn) TaskList(prefix string, limit int, skip int, opts ...*ListOpts) ([]Task, 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) TopicCount(prefix string, opts ...*CountOpts) (interface{}, error)
- func (nc *NexusConn) TopicList(prefix string, limit int, skip int, opts ...*ListOpts) ([]TopicInfo, 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) (interface{}, error)
- func (nc *NexusConn) UserAddBlacklist(user, ip string) (interface{}, error)
- func (nc *NexusConn) UserAddTemplate(user, template string) (interface{}, error)
- func (nc *NexusConn) UserAddWhitelist(user, ip string) (interface{}, error)
- func (nc *NexusConn) UserCount(prefix string, opts ...*CountOpts) (interface{}, error)
- func (nc *NexusConn) UserCreate(user, pass string) (interface{}, error)
- func (nc *NexusConn) UserDelBlacklist(user, ip 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) UserDelWhitelist(user, ip string) (interface{}, error)
- func (nc *NexusConn) UserDelete(user string) (interface{}, error)
- func (nc *NexusConn) UserGetEffectiveTags(user string, prefix string) (interface{}, error)
- func (nc *NexusConn) UserGetTags(user string) (interface{}, error)
- func (nc *NexusConn) UserList(prefix string, limit int, skip int, opts ...*ListOpts) ([]UserInfo, error)
- func (nc *NexusConn) UserRename(user string, new string) (interface{}, error)
- func (nc *NexusConn) UserSetDisabled(user string, disabled bool) (interface{}, error)
- func (nc *NexusConn) UserSetMaxSessions(user string, sessions int) (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)
- func (nc *NexusConn) Version() (interface{}, error)
- type NodeInfo
- type NxVersion
- 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)
- func (p *Pipe) WriteN(msgs []interface{}) (interface{}, error)
- type PipeData
- type PipeOpts
- type SessionInfo
- type Task
- type TaskOpts
- type TopicData
- type TopicInfo
- type TopicMsg
- type UserInfo
- type UserSessions
Constants ¶
const ( ErrParse = -32700 ErrInvalidRequest = -32600 ErrInternal = -32603 ErrInvalidParams = -32602 ErrMethodNotFound = -32601 ErrTtlExpired = -32011 ErrPermissionDenied = -32010 ErrConnClosed = -32007 ErrLockNotOwned = -32006 ErrUserExists = -32005 ErrInvalidUser = -32004 ErrInvalidPipe = -32003 ErrInvalidTask = -32002 ErrCancel = -32001 ErrTimeout = -32000 ErrNotSupported = -32099 )
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", ErrLockNotOwned: "Lock not owned", ErrConnClosed: "Connection is closed", ErrNotSupported: "Not supported", }
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 CountOpts ¶
type CountOpts struct { Subprefixes bool // Include the count of the subprefixes Filter string // A RE2 regular expression to filter prefixes on the search }
CountOpts represents the common options when requesting a count
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 ListOpts ¶
type ListOpts struct { LimitByDepth bool // Enables the limit of the search to a number of subprefixes Depth int // If LimitByDepth is true, this depth is used (0 means the exact prefix) Filter string // A RE2 regular expression to filter prefixes on the search }
ListOpts represents the common options when requesting a list
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 { NexusVersion *NxVersion // 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) LockCount ¶
LockCount counts locks from Nexus. Returns the response object from Nexus or error.
func (*NexusConn) LockList ¶
func (nc *NexusConn) LockList(prefix string, limit int, skip int, opts ...*ListOpts) ([]LockInfo, error)
LockList lists locks from Nexus. Returns a list of LockInfo or error.
func (*NexusConn) Login ¶
Login attempts to login using user and pass. Returns the response object from Nexus or error.
func (*NexusConn) Node ¶
Node returns info of the node the client is connected Returns NodeInfo struct or an 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) SessionCount ¶
SessionCount counts sessions from Nexus session's table. 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 ¶
func (nc *NexusConn) SessionList(prefix string, limit int, skip int, opts ...*ListOpts) ([]UserSessions, error)
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) SetInactivityTimeout ¶
SetSessionExpirationTimeout sets an expiration timeout. When it is reached the connection will be closed
func (*NexusConn) TaskCount ¶
TaskCount counts task pushes and pulls from Nexus task's table. Returns the response object from Nexus or error.
func (*NexusConn) TaskList ¶
func (nc *NexusConn) TaskList(prefix string, limit int, skip int, opts ...*ListOpts) ([]Task, error)
TaskList returns how many push/pulls are happening on a path and its children 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) TopicCount ¶
TopicCount counts subscriptions to topics from Nexus. Returns the response object from Nexus or error.
func (*NexusConn) TopicList ¶
func (nc *NexusConn) TopicList(prefix string, limit int, skip int, opts ...*ListOpts) ([]TopicInfo, error)
TopicList lists subscriptions to topics from Nexus. Returns a list of TopicInfo or error.
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) UserAddBlacklist ¶
UserAddBlacklist adds an IP to the user's blacklist. IP is a regex that will be matched against the client source address 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) UserAddWhitelist ¶
UserAddWhitelist adds an IP to the user's whitelist. IP is a regex that will be matched against the client source address Returns the response object from Nexus or error.
func (*NexusConn) UserCount ¶
UserCount counts users from Nexus user's table. 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) UserDelBlacklist ¶
UserDelBlacklist removes an IP from the user's whitelist. IP is a regex that will be matched against the client source address 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) UserDelWhitelist ¶
UserDelWhitelist removes an IP from the user's whitelist. IP is a regex that will be matched against the client source address 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) UserGetEffectiveTags ¶
UserGetEffectiveTags gets the user effective tags on a prefix (higher tags on hierachy will overwrite lower ones) Returns the response object from Nexus or error.
func (*NexusConn) UserGetTags ¶
UserGetTags gets the user tags Returns the response object from Nexus or error.
func (*NexusConn) UserList ¶
func (nc *NexusConn) UserList(prefix string, limit int, skip int, opts ...*ListOpts) ([]UserInfo, error)
UserList lists users from Nexus user's table. Returns a list of UserInfo or error.
func (*NexusConn) UserRename ¶
UserRename changes the name of a user from Nexus user's table. Returns the response object from Nexus or error.
func (*NexusConn) UserSetDisabled ¶
UserSetDisable set disable flag on an user Setting the value to true will prevent any login from this user Returns the response object from Nexus or error.
func (*NexusConn) UserSetMaxSessions ¶
UserSetMaxSessions set the maximum number of sessions a client can open Setting the value lower than the current number of sessions won't kill any session 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.
func (*Pipe) TopicRead ¶
TopicRead reads up to (max) topic messages from pipe or until timeout occurs.
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 { Id string `json:"id"` Stat string `json:"state"` Path string `json:"path"` Prio int `json:"priority"` Ttl int `json:"ttl"` Detach bool `json:"detached"` User string `json:"user"` Method string `json:"method"` Params interface{} `json:"params"` LocalId interface{} `json:"-"` Tses string `json:"targetSession"` Result interface{} `json:"result"` ErrCode *int `json:"errCode"` ErrStr string `json:"errString"` ErrObj interface{} `json:"errObject"` Tags map[string]interface{} `json:"tags"` CreationTime time.Time `json:"creationTime"` DeadLine time.Time `json:"deadline"` // contains filtered or unexported fields }
Task represents a task pushed to Nexus.
func NewTask ¶
NewTask creates a new task with the provided Nexus connection. Usually tasks are created on TaskPull, but this method is usefull for testing purposes.
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 UserInfo ¶
type UserInfo struct { User string `json:"user"` CreatedAt time.Time `json:"createdAt"` Tags map[string]map[string]interface{} `json:"tags"` Templates []string `json:"templates"` Whitelist []string `json:"whitelist"` Blacklist []string `json:"blacklist"` MaxSessions int `json:"maxsessions"` Disabled bool `json:"disabled"` }
type UserSessions ¶
type UserSessions struct { User string `json:"user"` Sessions []SessionInfo `json:"sessions"` N int `json:"n"` }