event

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

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

func (e Event) Command() (string, error)

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

func (e Event) Data() ([]byte, error)

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

func (e Event) From() (cid.Cid, error)

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

func (e Event) Protocol() (string, error)

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) To added in v0.1.19

func (e Event) To() (cid.Cid, error)

To returns a cid.Cid of the sending node and an error.

func (Event) Write

func (e Event) Write(data []byte) error

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!

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL