Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelObject ¶
type ChannelObject struct {
// contains filtered or unexported fields
}
func Channel ¶
func Channel(name string) (*ChannelObject, error)
Channel will create a new ChannelObject based on the provided name returns a ChannelObject and an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/pubsub/node" pubsub "github.com/taubyte/go-sdk/pubsub/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := symbols.MockData{ Channel: "someChannel", WebSocketURL: "ws-QmQq71tkq1yKmYobFUhPWF2MejK5CrvpY4h7HQDDT8b8Zb/someChannel", }.Mock() channel, err := pubsub.Channel("someChannel") if err != nil { return } fmt.Println("Name:", channel.Name()) err = channel.Subscribe() if err != nil { return } fmt.Println("Subscriptions:", m.Subscriptions) err = channel.Publish([]byte("Hello, world!")) if err != nil { return } fmt.Println("Published:", string(m.PublishedData)) url, err := channel.WebSocket().Url() if err != nil { return } fmt.Println("Url:", url.Path) }
Output: Name: someChannel Subscriptions: [someChannel] Published: Hello, world! Url: ws-QmQq71tkq1yKmYobFUhPWF2MejK5CrvpY4h7HQDDT8b8Zb/someChannel
func (*ChannelObject) Publish ¶
func (c *ChannelObject) Publish(data []byte) error
Publish will publish provided data onto the pub-sub channel returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/pubsub/node" pubsub "github.com/taubyte/go-sdk/pubsub/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := symbols.MockData{ Channel: "someChannel", }.Mock() channel, err := pubsub.Channel("someChannel") if err != nil { return } err = channel.Publish([]byte("Hello, world!")) if err != nil { return } fmt.Println("Published:", string(m.PublishedData)) }
Output: Published: Hello, world!
func (*ChannelObject) Subscribe ¶
func (c *ChannelObject) Subscribe() error
Subscribe tells a node to subscribe to a given pub-sub channel returns an error
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/pubsub/node" pubsub "github.com/taubyte/go-sdk/pubsub/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := symbols.MockData{ Channel: "someChannel", }.Mock() channel, err := pubsub.Channel("someChannel") if err != nil { return } err = channel.Subscribe() if err != nil { return } fmt.Println("Subs:", m.Subscriptions) }
Output: Subs: [someChannel]
func (*ChannelObject) WebSocket ¶
func (c *ChannelObject) WebSocket() WebSocket
Example ¶
package main import ( "fmt" symbols "github.com/taubyte/go-sdk-symbols/pubsub/node" pubsub "github.com/taubyte/go-sdk/pubsub/node" ) func main() { // Mocking the calls to the vm for usage in tests and playground symbols.MockData{ Channel: "someChannel", WebSocketURL: "ws-QmQq71tkq1yKmYobFUhPWF2MejK5CrvpY4h7HQDDT8b8Zb/someChannel", }.Mock() channel, err := pubsub.Channel("someChannel") if err != nil { return } url, err := channel.WebSocket().Url() if err != nil { return } fmt.Println("URL:", url.Path) }
Output: URL: ws-QmQq71tkq1yKmYobFUhPWF2MejK5CrvpY4h7HQDDT8b8Zb/someChannel
Click to show internal directories.
Click to hide internal directories.