Files
m3o-go/examples/stream
2021-11-03 11:49:43 +00:00
..
2021-11-03 11:49:43 +00:00
2021-11-03 10:19:08 +00:00
2021-11-03 11:49:43 +00:00

Stream

An m3o.com API. For example usage see m3o.com/Stream/api.

Endpoints:

Publish

Publish a message to the stream. Specify a topic to group messages for a specific topic.

https://m3o.com/stream/api#Publish

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stream"
)

// Publish a message to the stream. Specify a topic to group messages for a specific topic.
func PublishAmessage() {
	streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := streamService.Publish(&stream.PublishRequest{
		Message: map[string]interface{}{
	"user": "john",
	"id": "1",
	"type": "signup",
},
Topic: "events",

	})
	fmt.Println(rsp, err)
}

Subscribe

Subscribe to messages for a given topic.

https://m3o.com/stream/api#Subscribe

package example

import(
	"fmt"
	"os"

	"go.m3o.com/stream"
)

// Subscribe to messages for a given topic.
func SubscribeToAtopic() {
	streamService := stream.NewStreamService(os.Getenv("M3O_API_TOKEN"))
	rsp, err := streamService.Subscribe(&stream.SubscribeRequest{
		Topic: "events",

	})
	fmt.Println(rsp, err)
}