Commit from m3o/m3o action

This commit is contained in:
m3o-actions
2021-10-29 06:38:17 +00:00
parent 87f310675d
commit ae73a4aca1
170 changed files with 6189 additions and 42 deletions

65
examples/stream/README.md Executable file
View File

@@ -0,0 +1,65 @@
# Stream
An [m3o.com](https://m3o.com) API. For example usage see [m3o.com/Stream/api](https://m3o.com/Stream/api).
Endpoints:
## Subscribe
Subscribe to messages for a given topic.
[https://m3o.com/stream/api#Subscribe](https://m3o.com/stream/api#Subscribe)
```go
package example
import(
"fmt"
"os"
"github.com/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)
}
```
## Publish
Publish a message to the stream. Specify a topic to group messages for a specific topic.
[https://m3o.com/stream/api#Publish](https://m3o.com/stream/api#Publish)
```go
package example
import(
"fmt"
"os"
"github.com/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{}{
"id": "1",
"type": "signup",
"user": "john",
},
Topic: "events",
})
fmt.Println(rsp, err)
}
```