kite: github.com/koding/kite/dnode Index | Files

package dnode

import "github.com/koding/kite/dnode"

Package dnode implements a dnode scrubber. See the following URL for details: https://github.com/substack/dnode-protocol/blob/master/doc/protocol.markdown

Index

Package Files

callback.go errors.go message.go partial.go scrub.go scrubber.go unscrub.go

func ParseCallbacks Uses

func ParseCallbacks(msg *Message, sender func(id uint64, args []interface{}) error) error

parseCallbacks parses the message's "callbacks" field and prepares callback functions in "arguments" field.

type ArgumentError Uses

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

ArgumentError is returned when received message contains invalid arguments.

func (ArgumentError) Error Uses

func (e ArgumentError) Error() string

type CallbackNotFoundError Uses

type CallbackNotFoundError struct {
    ID   uint64
    Args *Partial
}

CallbackNotFoundError is returned when there is no registered callback for received message.

func (CallbackNotFoundError) Error Uses

func (e CallbackNotFoundError) Error() string

type CallbackSpec Uses

type CallbackSpec struct {
    // Path represents the callback's path in the arguments structure.
    Path     Path
    Function Function
}

CallbackSpec is a structure encapsulating a Function and it's Path. It is the type of the values in callbacks map.

type Function Uses

type Function struct {
    Caller caller
}

Function is the type for sending and receiving functions in dnode messages.

func Callback Uses

func Callback(f func(*Partial)) Function

Callback is the wrapper for function when sending.

func (Function) Call Uses

func (f Function) Call(args ...interface{}) error

Call the received function.

func (Function) IsValid Uses

func (f Function) IsValid() bool

IsValid returns true if f represents a Function. It returns false if f is the zero Value.

func (Function) MarshalJSON Uses

func (f Function) MarshalJSON() ([]byte, error)

func (*Function) UnmarshalJSON Uses

func (*Function) UnmarshalJSON(data []byte) error

type Message Uses

type Message struct {
    // Method can be an integer or string.
    Method interface{} `json:"method"`

    // Array of arguments
    Arguments *Partial `json:"arguments"`

    // Integer map of callback paths in arguments
    Callbacks map[string]Path `json:"callbacks"`
}

Message is the JSON object to call a method at the other side.

type MethodNotFoundError Uses

type MethodNotFoundError struct {
    Method string
    Args   *Partial
}

MethodNotFoundError is returned when there is no registered handler for received method.

func (MethodNotFoundError) Error Uses

func (e MethodNotFoundError) Error() string

type Partial Uses

type Partial struct {
    Raw           []byte
    CallbackSpecs []CallbackSpec
}

Partial is the type of "arguments" field in dnode.Message.

func (*Partial) Bool Uses

func (p *Partial) Bool() (b bool, err error)

Bool is a helper to unmarshal a JSON Boolean.

func (*Partial) Float64 Uses

func (p *Partial) Float64() (f float64, err error)

Float64 is a helper to unmarshal a JSON Number.

func (*Partial) Function Uses

func (p *Partial) Function() (f Function, err error)

Function is a helper to unmarshal a callback function.

func (*Partial) Map Uses

func (p *Partial) Map() (m map[string]*Partial, err error)

Map is a helper method to unmarshal to a JSON Object.

func (*Partial) MarshalJSON Uses

func (p *Partial) MarshalJSON() ([]byte, error)

MarshalJSON returns the raw bytes of the Partial.

func (*Partial) MustBool Uses

func (p *Partial) MustBool() bool

func (*Partial) MustFloat64 Uses

func (p *Partial) MustFloat64() float64

func (*Partial) MustFunction Uses

func (p *Partial) MustFunction() Function

func (*Partial) MustMap Uses

func (p *Partial) MustMap() map[string]*Partial

func (*Partial) MustSlice Uses

func (p *Partial) MustSlice() []*Partial

func (*Partial) MustSliceOfLength Uses

func (p *Partial) MustSliceOfLength(length int) []*Partial

func (*Partial) MustString Uses

func (p *Partial) MustString() string

func (*Partial) MustUnmarshal Uses

func (p *Partial) MustUnmarshal(v interface{})

func (*Partial) One Uses

func (p *Partial) One() *Partial

func (*Partial) Slice Uses

func (p *Partial) Slice() (a []*Partial, err error)

Slice is a helper method to unmarshal a JSON Array.

func (*Partial) SliceOfLength Uses

func (p *Partial) SliceOfLength(length int) (a []*Partial, err error)

SliceOfLength is a helper method to unmarshal a JSON Array with specified length.

func (*Partial) String Uses

func (p *Partial) String() (s string, err error)

String is a helper to unmarshal a JSON String.

func (*Partial) Unmarshal Uses

func (p *Partial) Unmarshal(v interface{}) error

Unmarshal unmarshals the raw data (p.Raw) into v and prepares callbacks. v must be a struct that is the type of expected arguments.

func (*Partial) UnmarshalJSON Uses

func (p *Partial) UnmarshalJSON(data []byte) error

UnmarshalJSON puts the data into Partial.Raw.

type Path Uses

type Path []interface{}

Path represents a callback function's path in the arguments structure. Contains mixture of string and integer values.

type Scrubber Uses

type Scrubber struct {

    // Reference to sent callbacks are saved in this map.
    sync.Mutex // protects
    // contains filtered or unexported fields
}

func NewScrubber Uses

func NewScrubber() *Scrubber

New returns a pointer to a new Scrubber.

func (*Scrubber) GetCallback Uses

func (s *Scrubber) GetCallback(id uint64) func(*Partial)

func (*Scrubber) RemoveCallback Uses

func (s *Scrubber) RemoveCallback(id uint64)

RemoveCallback removes the callback with id from callbacks. Can be used to remove unused callbacks to free memory.

func (*Scrubber) Scrub Uses

func (s *Scrubber) Scrub(obj interface{}) (callbacks map[string]Path)

Scrub creates an object that represents "callbacks" field in dnode message. The obj argument which will be scrubbed must be of array, slice, struct, or map type. If structure is passed, the returned callbacks map will contain its exported methods of func(*Partial) signature. Other functions must be wrapped by Callback function.

func (*Scrubber) Unscrub Uses

func (s *Scrubber) Unscrub(arguments interface{}, callbacks map[string]Path, f func(uint64) functionReceived) error

Package dnode imports 8 packages (graph) and is imported by 33 packages. Updated 2017-02-06. Refresh now. Tools for package owners.