Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event uint32
Represents a p2p event.
func (Event) Command ¶
Command returns the command used to call the given p2p function and an error.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" ) func main() { var e event.Event // Event for a p2p function called by command, `someCommand` p2pEvent, err := e.P2P() if err != nil { return } command, err := p2pEvent.Command() if err != nil { return } fmt.Println(command) }
Output: someCommand
func (Event) Data ¶
Data returns the data sent to the function as bytes and an error.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" ) func main() { var e event.Event // Event for a p2p function called with data []byte("Hello, world!") p2pEvent, err := e.P2P() if err != nil { return } data, err := p2pEvent.Data() if err != nil { return } fmt.Println(string(data)) }
Output: Hello, world!
func (Event) From ¶
From returns a cid.Cid of the sending node and an error.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" ) func main() { var e event.Event // Event for a p2p function sent by a node with id: `Qmda9sdi214i9dsad` p2pEvent, err := e.P2P() if err != nil { return } cid, err := p2pEvent.From() if err != nil { return } fmt.Println(cid.KeyString()) }
Output: Qmda9sdi214i9dsad
func (Event) Protocol ¶
Protocol returns the protocol which the event was called and an error.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" ) func main() { var e event.Event // Event for a p2p function sent on protocol `/test/v1` p2pEvent, err := e.P2P() if err != nil { return } protocol, err := p2pEvent.Protocol() if err != nil { return } fmt.Println(protocol) }
Output: /test/v1
func (Event) Write ¶
Write writes given data and returns an error.
Example ¶
package main import ( "fmt" "bitbucket.org/taubyte/go-sdk/event" ) func main() { var e event.Event p2pEvent, err := e.P2P() if err != nil { return } err = p2pEvent.Write([]byte("Hello, world!")) if err != nil { return } var receiver event.Event receivedP2pEvent, err := receiver.P2P() if err != nil { return } data, err := receivedP2pEvent.Data() if err != nil { return } fmt.Println(string(data)) }
Output: Hello, world!
Click to show internal directories.
Click to hide internal directories.